• 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 fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

Laravel Command Schedule Not Working Properly

laravel MVC execution flow

Laravel query builder binding parameters more than once

How in Laravel run JavaScript code stored in php variable?

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

laravel 5.6 bulk inserting json data

Call to a member function givePermissionTo() on null

Laravel Excel::store file empty after stored

401 Unauthorized only occurring on some pages in Laravel 8

phpunit - mockbuilder - set mock object internal property

Detect emoticons in string

Laravel SQL query midnight time not showing

image source not readable

About Contact Privacy policy Terms and conditions