moon0326 / FakeMiddleware by moon0326

A small Laravel 5 package to disable a middleware in testing environment
24,940
5
2
Package Data
Maintainer Username: moon0326
Maintainer Contact: kmk1986@gmail.com (Moon)
Package Create Date: 2015-04-17
Package Last Update: 2015-11-21
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:06:30
Package Statistics
Total Downloads: 24,940
Monthly Downloads: 37
Daily Downloads: 0
Total Stars: 5
Total Watchers: 2
Total Forks: 1
Total Open Issues: 0

FakeMiddleware

Sometimes you want to disable a middleware/route middleware when testing a controller in Laravel 5. This package simplifies the process.

Installation

composer require --dev "moon/fakemiddleware": "1.1"

Usage

Open TestCase.php, which comes with L5 by default. Locate createApplication method and initialize FakeMiddleware.


use Moon\FakeMiddleware\FakeMiddleware;

public function createApplication()
{
    $app = require __DIR__.'/../bootstrap/app.php';
    $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

    // This will remove ExternalOAuthVerifier and repalce auth middleware
    // with a fake middleware
    // function __construct(Application $app, $globalMiddlewares, $routeMiddlewares);
    new FakeMiddleware($app, ['App\Http\Middleware\ExternalOAuthVerifier'], ['auth']);

    return $app;
}