• 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 7: Failed asserting that exception of type InvalidArgumentException is thrown

How in Laravel run JavaScript code stored in php variable?

How to KeyBy where multiple items have the same key

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

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

Form repeater send wrong data with last element in Laravel

Check if user online laravel

PHPUnit - REST API testing

laravel sanctum Route [login] not defined

How to check user Permissions using Custom Middleware in Laravel

I need to link Google Sheet with my Laravel

How to set a domain name with php artisan serve

Problem with fetching data from database in Laravel

Parameter is not sent to Laravel route in Ajax

Using spatie/media-library, how to rename a collection of uploaded files?

About Contact Privacy policy Terms and conditions