Reputation: 4795
Is there a way to turn off some Laravel 5.0 middleware for functional tests?
Upvotes: 0
Views: 335
Reputation: 4795
I've found simple solution, although probably it may be not "TRUE", but it works. I've modified method handle() in my app/Http/Middleware/VerifyCsrfToken.php to this
public function handle($request, Closure $next)
{
if (env('APP_ENV') === 'testing') {
return $next($request);
}
return parent::handle($request, $next);
}
Upvotes: 0
Reputation: 15579
Just edit app/Http/kernel.php
file and comment any undesired middleware line in array $middleware
.
You don't need to comment the ones in $routeMiddleware
since these won't be automatically called, and they need to be specifically activated in the routes.php
file.
Another way:
Copy Kernel.php
as Kerneltest.php
in the same folder.
Then rename the class in Kerneltest.php to Kerneltest
and make it extends Kernel
.
Then remove any middleware lines from Kerneltest
Then add the following to bootstrap\app.php
:
$app->singleton(
'Illuminate\Contracts\Http\Kerneltest',
'App\Http\Kerneltest'
);
Then in public\index.php
use
$kernel = $app->make('Illuminate\Contracts\Http\Kerneltest');
or
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
depending on whether you're testing or not.
Upvotes: 2