• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

How to Mock the Request Class in Laravel?

laravelmockingphpunit


PHP Snippet 1:

app()->bind(\Illuminate\Http\Request::class, function () {
    $mock = \Mockery::mock(\Illuminate\Http\Request::class)->makePartial();
    $mock->shouldReceive('all')->andReturn(['includes' => ['some_val','another_val']]);

    return $mock;
});

PHP Snippet 2:

public function testPostRequest() {
    $response = $this->post(
        '/my-custom-route',
        ['includes' => ['some_val','another_val']]
    );
}

Related Snippets

Target Laravelista is not instantiable

Laravel Jetsream Profile page not loading on fresh install

Login if user is active using Laravel Breeze

How to check user Permissions using Custom Middleware in Laravel

Use same method for inertia response and json response Laravel Jetstream

Fetch files from next cloud storage and display in Laravel website

Cannot connect to own websocket server when on secured domain

Image upload not working through ajax Laravel

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Check if user online laravel

Form repeater send wrong data with last element in Laravel

Laravel 5 issue with wherePivot

How do I call Validator from a namespace with an already existing Validator class

laravel and phpunit: could not find driver (SQL: PRAGMA foreign_keys = ON;)

Laravel Collections. Is there some kind of assertStructure method?

About Contact Privacy policy Terms and conditions