• 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

Symfony process run throws exception - executing on command line works

Target Laravelista is not instantiable

500 (Internal Server Error) with Laravel & Docker [duplicate]

How can I pass the list to the component variable in Laravel?

"There is no active transaction" when refreshing database in Laravel 8.0 test

MySQL upgrade causing unexpected results on simple WHERE clauses

How in Laravel run JavaScript code stored in php variable?

Laravel Mix Uncaught ReferenceError: $ is not defined

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

PHP Fatal error: Class not found - PHPUnit

I need to link Google Sheet with my Laravel

set mail driver dynamically from database for different email in notification

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

How to convert binary string to normal string in php

Laravel Delete and Update

About Contact Privacy policy Terms and conditions