jasonmccreary / laravel-test-assertions

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

Add assertion to route group middleware #44

Closed devonmather closed 1 year ago

devonmather commented 1 year ago

Long time user of this package, thanks again for making it! Recently, I found it difficult to make assertions on middleware nested within a middleware group. In order to hopefully not create backward compatibility issues by heavily refactoring the assertRouteUsesMiddleware I have opted for a new assertion method to be added called assertMiddlewareGroupUsesMiddleware.

An example usage of this new function may look something like this.

/** @test */
public function route_uses_desired_middleware(): void
{
     // Below we check if the middleware group is used with existing functionality
    $this->assertRouteUsesMiddleware('welcome.show', ['web']);
    // Next we can use the new assertion to be sure the `web` group uses specific middleware(s)
    $this->assertMiddlewareGroupUsesMiddleware('web', [HandleInertiaRequests::class]); 
}

I noticed there isn't a test suite in the package to run, I did some manual testing and everything seemed to work fine, but please advise if there's any test coverage that can be added somewhere or changes that may be desired ✌️

jasonmccreary commented 1 year ago

Yeah, this was one of my first packages and while I still use it, is a bit dated when it comes to the latest conventions.

As such, I'm going to merge this blindly, but will not tag it for a bit. You can point at dev-master to use it in your project.

devonmather commented 11 months ago

Awesome thanks updated to dev-master, will report if anything goes amiss 🤝