• 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 Carbon get start + end of last week?

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

How to generate QR CODE for dynamic generating link and logo using Simple QrCode in laravel?

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

Create tags in laravel post publishing

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

laravel 5.6 bulk inserting json data

Laravel Schedule not sending email

Laravel/ PHP: Order By Alphabetical with numbers in order [duplicate]

add uri parameter to Route name in laravel

MySQL upgrade causing unexpected results on simple WHERE clauses

Too few arguments to function PendingResourceRegistration::name(),1 passed in C:xampphtdocsproject outesweb.php on line 18 and exactly 2 expected

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

image source not readable

How to Make Laravel Eloquent "IN" Query?

About Contact Privacy policy Terms and conditions