jasonmccreary / laravel-test-assertions

A set of helpful assertions when testing Laravel applications.
321 stars 34 forks source link

Adds assertRouteUsesMiddleware assertion #22

Closed niveshsaharan closed 4 years ago

niveshsaharan commented 4 years ago

Added a handy method to check if a route uses given set of middlewares and option to check if it uses only the given set of middlewares.

I needed this to use in one of my application so I thought I'd create a pull request and maybe other people can find it useful.

jasonmccreary commented 4 years ago

Nice. But what is onlyThese? How is it used?

niveshsaharan commented 4 years ago

$onlyThese checks if the route has only the expected middlewares. For example, I want to check if route 'home' uses only 'web' and 'auth' middlewares and nothing else:

$this->assertRouteUsesMiddleware('home', ['web', 'auth'], true);

The test will fail if the route has any other middleware than these 2.

jasonmccreary commented 4 years ago

I see. Could you rename to only, exact, or strict. Your choice.

Also, could you ensure you code mets the project coding standard (PSR-2).