• 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

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

How to pass data to all views in Laravel 5?

How to render html from a @foreach loop in a textarea

Laravel implode array items to new lines

Passing a boolean value from checkbox in Laravel form

dockerizing Laravel + vue

Use same method for inertia response and json response Laravel Jetstream

Laravel csrf token mismatch for ajax POST Request

Laravel database insert with combining array and string

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

Laravel 8: Array to string conversion while calling route:list

How in Laravel run JavaScript code stored in php variable?

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

laravel automatically deletes server.php on php artisan serve

How to to send mail using gmail in Laravel?

About Contact Privacy policy Terms and conditions