• 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

Cannot connect to own websocket server when on secured domain

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

Losing session data after POST from third party website

How to use React Router with Laravel?

Laravel implode array items to new lines

Star and Half Star Rating in Laravel

Laravel get user data with profile

Laravel 5 session not persisting after user is logged in

Laravel Get Days In Month From Month Number?

How to make a foreign key not using primary key

Laravel SQL query midnight time not showing

How to get array values using foreach in laravel

Laravel 5 controller sending JSON integer as string

Laravel UUID generation

Detect emoticons in string

About Contact Privacy policy Terms and conditions