• 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

How to Display Data in Yajra Datatables Laravel 7?

Cache clear probem in Larave

Too few arguments to function PendingResourceRegistration::name(),1 passed in C:xampphtdocsproject outesweb.php on line 18 and exactly 2 expected

How to get unique slug to same post-title for other time too?

How in Laravel run JavaScript code stored in php variable?

500 (Internal Server Error) with Laravel & Docker [duplicate]

How to check user Permissions using Custom Middleware in Laravel

Target Laravelista is not instantiable

Laravel Schedule not sending email

Laravel SQL query midnight time not showing

Target class controller does not exist - Laravel 8

MySQL upgrade causing unexpected results on simple WHERE clauses

Laravel Collections. Is there some kind of assertStructure method?

Passing a boolean value from checkbox in Laravel form

How To Access A Column In M-M Relationship Table In Laravel

About Contact Privacy policy Terms and conditions