• 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 laravel storage symbolic link for production or sub domain system?

Show date difference as "20" instead of "20 years ago"

Natural ORDER in Laravel Eloquent ORM

laravel MVC execution flow

enroll_table three field fetch to payment form to create payment field in laravel 5.5

JSON Render Issue in Date Object Laravel and PHP 7.4

Passing a boolean value from checkbox in Laravel form

Cache clear probem in Larave

Laravel: HTML in notification

oauth-private.key does not exist or is not readable

Log a user out of a website when they put their computer to sleep

Laravel: Create morphs() relationship nullable

Laravel phpunit test failing authorization

Laravel s3 upload file with metadata using pre-signed url

Eloquent insert id with sequence next value

About Contact Privacy policy Terms and conditions