• 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

"There is no active transaction" when refreshing database in Laravel 8.0 test

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

Assets not referencing to public folder (Laravel)

How to check user Permissions using Custom Middleware in Laravel

"There is no active transaction" when refreshing database in Laravel 8.0 test

auth pages not getting css in laravel

Make survey at laravel 5.4 and MySQL

How to create laravel storage symbolic link for production or sub domain system?

How to get unique slug to same post-title for other time too?

laravel 5.6 bulk inserting json data

Method IlluminateAuthRequestGuard::logout does not exist Laravel Passport

Laravel/docker-compose/redis - Class 'Redis' not found

Laravel relationship belongsToMany with composite primary keys

I need to link Google Sheet with my Laravel

Access relation of pivot table in Laravel

About Contact Privacy policy Terms and conditions