• 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

auth pages not getting css in laravel

carbon generated datetime not stored correctly into the database

PHPUnit - REST API testing

Symfony - "framework.test" config is not set to true

Fetch files from next cloud storage and display in Laravel website

set mail driver dynamically from database for different email in notification

Laravel Delete and Update

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

Laravel + phpunit + github actions = Failed asserting that '1' is identical to 1

Failing validation doesn't stop code execution in livewire component

What will the best solution for this multiple optional filter?

Create tags in laravel post publishing

How to pass data to all views in Laravel 5?

How do I call Validator from a namespace with an already existing Validator class

Laravel dosen't connect with Oracle

About Contact Privacy policy Terms and conditions