• 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

Laravel + phpunit + github actions = Failed asserting that '1' is identical to 1

how to sort by a custom appended relation to model

how to upload binary image to sql server using php laravel

Laravel display validation error

How to get array values using foreach in laravel

Laravel Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttpPsr7Request

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Symfony process run throws exception - executing on command line works

Laravel 5 issue with wherePivot

Laravel Livewire: jQuery not working in child component loaded via @if statement

Add bold text and line break into Laravel Notification Email

Laravel Blade checkbox not checked

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

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

Required field only if another field has a value, must be empty otherwise

About Contact Privacy policy Terms and conditions