• 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

PHPUnit (Phar) Fatal Error Only When Test Fails

PHP using str_starts_with for array to exclude same as with wildcard

Laravel Schedule not sending email

Is there a way to use Foundry Model for Authentification inside Functional Tests?

file_put_content...fail to open stream:Permission denied in Laravel 5

How to get result of the formula on import xlsx with maatwebsite using Laravel? I get formula and not value of the formula

Create tags in laravel post publishing

auth pages not getting css in laravel

Unit (real unit test) of test laravel relationship

How can I pass the list to the component variable in Laravel?

Issue with laravel eloquent model property

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

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

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

laravel controller function parameters

About Contact Privacy policy Terms and conditions