Framework: Support for disabling the specific middleware in testing

Created on 5 Jan 2016  路  4Comments  路  Source: laravel/framework

In some cases while testing, there is requirement for unit test cases to disable specific middle ware rather than all middle wares. i have searched in documentation and code there is no option like this so i'm suggesting this feature.

Most helpful comment

Hopefully PR #18673 in forthcoming L5.5 will provide a clean solution

All 4 comments

Sorry, this isn't planned, because the application object has a method on it called runningUnitTests(). Just check that within your middleware code itself.

That's how our csrf middleware works from 5.2+.

Unfortunately in 5.2 the CSRF middleware runningUnitTests() method uses both this->app->runningInConsole() and $this->app->runningUnitTests().

I would like to disable the CSRF middleware (but not any other middleware) so that I can use Codeception's PHPBrowser module.

I can change my .env file to cause the runningUnitTests() method to return true however the runningInConsole() method returns false with PHPBrowser.

TL;DR; There is still a valid use case for disabling specific middleware--Laravel's or others'--in order to facilitate testing.

Hopefully PR #18673 in forthcoming L5.5 will provide a clean solution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

YannPl picture YannPl  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments