• 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

image source not readable

Target class controller does not exist - Laravel 8

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

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

Artisan, creating tables in database

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Laravel excel maatwebsite 3.1 import, date column in excel cell returns as unknown format number. How to solve this?

Class AppHttpControllersUserController Does Not Exist

How to make a foreign key not using primary key

SQLSTATE[HY000]: General error: 1 table posts has no column named *

carbon generated datetime not stored correctly into the database

Star and Half Star Rating in Laravel

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

Issue with laravel eloquent model property

Laravel Collections. Is there some kind of assertStructure method?

About Contact Privacy policy Terms and conditions