• 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 query builder binding parameters more than once

Laravel 5.5 change unauthenticated login redirect url

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

Laravel: HTML in notification

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

Laravel MSSQL Server Connection not working

Laravel 5 session not persisting after user is logged in

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

How to get array values using foreach in laravel

How do I upload a laravel project on cPanel shared hosting?

Maatwebsite Excel 3.1 : how do I skip duplicate data when imported?

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

How can I resolve "Your requirements could not be resolved to an installable set of packages" error?

image source not readable

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

About Contact Privacy policy Terms and conditions