• 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

PHPUnit - REST API testing

image source not readable

Laravel Factory not calling callback 'afterCreating'

Autoloading classes in PHPUnit using Composer and autoload.php

Laravel PackageManifest.php: Undefined index: name

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

401 Unauthorized only occurring on some pages in Laravel 8

target [LaravelFortifyContractsRegisterViewResponse] is not instantiable

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

I need to link Google Sheet with my Laravel

How to get quarter for future date using Carbon?

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

How in Laravel run JavaScript code stored in php variable?

Laravel Collections. Is there some kind of assertStructure method?

Login if user is active using Laravel Breeze

About Contact Privacy policy Terms and conditions