• 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 - Browser displays message again when I press back button

How to convert binary string to normal string in php

Limit login attempts in Laravel 5.7

Laravel get user data with profile

Using spatie/media-library, how to rename a collection of uploaded files?

auth pages not getting css in laravel

How in Laravel run JavaScript code stored in php variable?

Natural ORDER in Laravel Eloquent ORM

Laravel SQL query midnight time not showing

Laravel php artisan serve to mimic HTTPS

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

How to fix Call to undefined method AppModelsTableName::factory?

PHPUnit - REST API testing

Laravel Sanctum CSRF not authenticating

Form repeater send wrong data with last element in Laravel

About Contact Privacy policy Terms and conditions