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.
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
Most helpful comment
Hopefully PR #18673 in forthcoming L5.5 will provide a clean solution