jasonmccreary/laravel-test-assertions

Use with Invoked Controllers

Closed this issue · 2 comments

Issue: The assertActionUsesMiddleware does not work with invoke methods

Resolution: Change the following lines [52-53] in assertActionUsesMiddleware
$route = $router->getRoutes()->getByAction($controller . '@' . $method);
to

if($method) {
        $route = $router->getRoutes()->getByAction($controller . '@' . $method);
}
else {
        $route = $router->getRoutes()->getByAction($controller);
}

Then the usage would be $this->assertActionUsesMiddleware ('Controller', 'Method', 'Middleware'); for a method and $this->assertActionUsesMiddleware ('Controller', '', 'Middleware'); for invoked controllers

Thanks for reporting this. I believe the current solution would be to pass Controller@__invoke.

However, I will take a closer look.

Sorry for the 22 day response, but thank you for the update and release! Really helpful code here.