• 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 a view on laravel 8 and not have a 404 NOT FOUND page?

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

Laravel Collections. Is there some kind of assertStructure method?

Docker & Laravel : configure: error: Package requirements (oniguruma) were not met

find in set in laravel ? example

Laravel Command Schedule Not Working Properly

How to get Laravel's CSRF Token from Another Website?

Laravel whole batch is cancelled if one Job fails

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

Laravel insert dynamic input values with radio button

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

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

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

api response laravel doesn't show

Target Laravelista is not instantiable

About Contact Privacy policy Terms and conditions