• 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 create custom authentication in laravel 8?

add uri parameter to Route name in laravel

target [LaravelFortifyContractsRegisterViewResponse] is not instantiable

Make survey at laravel 5.4 and MySQL

Guzzle Not Sending Grant Type to Laravel Passport

Laravel Displaying image from database

How to properly start Laravel 8 with Bootstrap & authentication

dockerizing Laravel + vue

Losing session data after POST from third party website

could not find driver Debian SQL Server PHP

Laravel PackageManifest.php: Undefined index: name

Laravel passport auth token not working after moving to different server

Call authenticate manually in router middleware

How to to send mail using gmail in Laravel?

Laravel excel maatwebsite 3.1 import, date column in excel cell returns as unknown format number. How to solve this?

About Contact Privacy policy Terms and conditions