Hello,
please show your test code. Your test isn't included in the repository.
Also make sure that your test extends the Tests/TestCase class, and not the one from PHPUnit.
Hi! I have a Laravel package that adds web middleware but when phpunit runs a feature test, the middleware is not executed unless Laravel Sanctum is also installed. The middlware runs fine the browser.
I'm not allowed to post links yet but I have a fork showing the problem at github nolanpro/laravel-phpunit-middleware. You can compare it to see my changes.
In that repo, I added Route::pushMiddlewareToGroup('web', TestMiddleware::class); to AppServiceProvider. This is just to demonstrate how I'm actually adding middleware in a separate package.
I would expect to see "HERE IN MIDDLEWARE" when running phpunit but it's not there. When sanctum is installed I see it.
I've narrowed this down to the sanctum provider resolving Illuminate\Contracts\Http\Kernel early in the boot process, but without sanctum it resolves too late to.
One possible solution would be to add $app->make(\Illuminate\Contracts\Http\Kernel::class); to tests/CreatesApplication.php just above where it makes the console kernel. That seems to work but I don't know what the implications are of adding that and I'm reluctant to modify it without knowing.
Any help would be greatly appreciated! Thanks!
Please or to participate in this conversation.