Skip to content

Conversation

roberto-aguilar
Copy link
Contributor

This getter allows to create tests for the route middlewares, which is currently not possible because the property is protected.

For example, if you want to ensure that a route middleware has been registered, with this getter you can write:

/** @test */
public function it_registers_a_custom_route_middleware()
{
    $middlewares = resolve(\App\Http\Kernel::class)->getRouteMiddleware();

    $this->assertArrayHasKey('custom', $middlewares);
    $this->assertEquals(\App\Http\Middleware\Custom::class, $middlewares['custom']);
}

This is similar to #26268 but for the $routeMiddleware property.

@driesvints driesvints changed the title Create getter for the http route middlewares [5.8] Create getter for the http route middlewares Mar 11, 2019
This getter allows to create tests for the route
middlewares, which is currently not possible
because the property is protected.

For example, if you want to ensure that a route middleware has been
registered, with this getter you can write:

```php
/** @test */
public function it_registers_a_custom_route_middleware()
{
    $middlewares = resolve(\App\Http\Kernel::class)->getRouteMiddleware();

    $this->assertArrayHasKey('custom', $middlewares);
    $this->assertEquals(\App\Http\Middleware\Custom::class, $middlewares['custom']);
}
```
@taylorotwell taylorotwell merged commit fe2c8a6 into laravel:5.8 Mar 11, 2019
@roberto-aguilar roberto-aguilar deleted the feature/http-kernel branch March 11, 2019 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants