• 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 and phpunit: could not find driver (SQL: PRAGMA foreign_keys = ON;)

Clear javascript source cache laravel 5.8

Laravel SQL query midnight time not showing

PHP Fatal error: Class not found - PHPUnit

Xdebug in Laravel is not working with VSCode

Laravel Command Schedule Not Working Properly

How to reset Laravel AuthManager/guards in between API calls in tests?

How to convert a carbon into string, to take the date only?

500 (Internal Server Error) with Laravel & Docker [duplicate]

OctoberCMS / Anonymous Global Scope

Access denied for user 'homestead'@'localhost' (using password: YES)

Laravel 8 Multiple Relationships for Factory

Laravel Unknown Column 'updated_at'

laravel MVC execution flow

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

About Contact Privacy policy Terms and conditions