• 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

enroll_table three field fetch to payment form to create payment field in laravel 5.5

Laravel Database Strict Mode

LARAVEL: How to fetch id dynamically in a query builder?

Losing session data after POST from third party website

I want a way to give path to my files which are outside of public folder in laravel

How to make a foreign key not using primary key

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

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

How to change the app environment at run time?

How to create tests w/Doctrine entities without persisting them (how to set id)

Required field only if another field has a value, must be empty otherwise

Reducing authentication calls on external API (Laravel 5.6)

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

strpos(): Argument #1 ($haystack) must be of type string, array given

Laravel Excel::store file empty after stored

About Contact Privacy policy Terms and conditions