• 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

Autoloading classes in PHPUnit using Composer and autoload.php

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

target [LaravelFortifyContractsRegisterViewResponse] is not instantiable

Log file is not being written in Laravel 5.5

How to fix Call to undefined method AppModelsTableName::factory?

Call to a member function givePermissionTo() on null

Laravel Carbon get start + end of last week?

Issue with laravel eloquent model property

Remove categories with all childs derived from parent category

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

Laravel Excel::store file empty after stored

Laravel lang slug in url

How to fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

Respond with status code 401 on authentication failure using Laravel and Passport?

Show date difference as "20" instead of "20 years ago"

About Contact Privacy policy Terms and conditions