• 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

carbon generated datetime not stored correctly into the database

Is it possible to change the table name in the migration file-laravel

Error Class "LaravelFortifyFeatures" not found

How to make a foreign key not using primary key

Store multiple fields in JSON column (Nova CMS)

Losing session data after POST from third party website

Laravel PackageManifest.php: Undefined index: name

Failing validation doesn't stop code execution in livewire component

Laravel Displaying image from database

Parameter is not sent to Laravel route in Ajax

How in Laravel run JavaScript code stored in php variable?

How do I call Validator from a namespace with an already existing Validator class

Display Link Title Instead of URL in XSL

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

How to KeyBy where multiple items have the same key

About Contact Privacy policy Terms and conditions