• 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;)

Laravel Excel::store file empty after stored

(Laravel) How to delete multiple models including optional relationships?

how to fix Service provider class not found when using repository?

Access relation of pivot table in Laravel

Phpunit partial mock + proxy Entity

best way to store error messages in Laravel (session or variable)

Laravel 5 session not persisting after user is logged in

Laravel dosen't connect with Oracle

Sliders in Laravel

Error Class "LaravelFortifyFeatures" not found

Laravel Command Schedule Not Working Properly

Laravel Factory not calling callback 'afterCreating'

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

phpunit - mockbuilder - set mock object internal property

About Contact Privacy policy Terms and conditions