• 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

dockerizing Laravel + vue

Laravel - Implicit route model binding with soft deleted data

Autoloading classes in PHPUnit using Composer and autoload.php

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Convert date and time to Jalali in Laravel

How to test laravel controller method?

Laravel get user data with profile

Laravel Gates using model and returns "Using $this when not in object context" Line 28 of AzureUser model

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

How to check user Permissions using Custom Middleware in Laravel

Laravel 5.2: Unable to locate factory with name [default]

PHP using str_starts_with for array to exclude same as with wildcard

How to fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

Reducing authentication calls on external API (Laravel 5.6)

Show date difference as "20" instead of "20 years ago"

About Contact Privacy policy Terms and conditions