• 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

How to show selected value using javascript in laravel

Laravel Livewire: jQuery not working in child component loaded via @if statement

api response laravel doesn't show

Laravel query builder binding parameters more than once

Symfony - "framework.test" config is not set to true

Laravel + phpunit + github actions = Failed asserting that '1' is identical to 1

How to get Laravel's CSRF Token from Another Website?

Ajax GET request fails in laravel 8

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

Creating Combinations of Elements

Natural ORDER in Laravel Eloquent ORM

How to convert binary string to normal string in php

How to create tests w/Doctrine entities without persisting them (how to set id)

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

How to check user Permissions using Custom Middleware in Laravel

About Contact Privacy policy Terms and conditions