[6.x] aliasMiddleware doesn't work in test mode if 'router' overriden #33164
Unanswered
imanghafoori1
asked this question in
General
Replies: 2 comments
-
Moving to discussions. |
Beta Was this translation helpful? Give feedback.
0 replies
-
let me note that if we do the binding slightly different like below, it would fail again: <?php
public function register () {
$this->app->singleton('router', function ($app) {
return new SpyRouter(app('events'), app());
});
Route::swap($this->app->make('router'));
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description:
if we register our middlewares from a service provider like this:
app('router')->aliasMiddleware( 'myNiftyMiddleware', ... );
;and we also override the
'router'
on the container:everything is ok in a normal web request, but when we run tests it throws the error:
I discovered it while the laravel-microscope was installed (which overrides the router with a sub-class of it) and middlewares were registered by
aliasMiddleware
from a service provider.So if any package is installed on a project which overrides the default core
router
and user-space code uses
aliasMiddleware()
to register middlewares. (in case they want to create a package or create a modular application)The tests can not be run on the endpoints which has that particular middleware on the way.
All and all, it is not severe and does not affect production at all.
but for modular architectures, this may become a headache.
Beta Was this translation helpful? Give feedback.
All reactions