• 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

Star and Half Star Rating in Laravel

How can i hide dt if dd got empty value

How to KeyBy where multiple items have the same key

Laravel 5.1 xmlHttpRequest AJAX POST TokenMismatchException

How can I make a full text index of the column?

Laravel Nova Dependency Container what are the allowed resource properties other than id in dependsOn

laravel automatically deletes server.php on php artisan serve

laravel sanctum Route [login] not defined

Laravel php artisan serve to mimic HTTPS

Laravel database insert with combining array and string

auth pages not getting css in laravel

Maatwebsite Excel 3.1 : how do I skip duplicate data when imported?

Creating command to backup MySql database in Laravel

Reducing authentication calls on external API (Laravel 5.6)

Error Class "LaravelFortifyFeatures" not found

About Contact Privacy policy Terms and conditions