• 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

Access denied for user 'homestead'@'localhost' (using password: YES)

Laravel implode array items to new lines

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work

PHPUNIT Test - Expected Status 200 But Received 500

Laravel 5.5 change unauthenticated login redirect url

How to Install Composer Require doctrine/dbal

Laravel Multi-language routes without prefix

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

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

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

image source not readable

Autoloading classes in PHPUnit using Composer and autoload.php

Laravel query builder binding parameters more than once

Whats the point of running Laravel with the command 'php artisan serve'?

About Contact Privacy policy Terms and conditions