Skip to content

Commit

Permalink
This getter allows to create tests for the route
Browse files Browse the repository at this point in the history
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)->getMiddlewareGroups();

    $this->assertArrayHasKey('custom', $middlewares);
    $this->assertEquals(\App\Http\Middleware\Custom::class, $middlewares['custom']);
}
```
  • Loading branch information
roberto-aguilar committed Mar 11, 2019
1 parent a3bbb7f commit 5e8515d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ public function getMiddlewareGroups()
return $this->middlewareGroups;
}

/**
* Get the application's route middleware.
*
* @return array
*/
public function getRouteMiddleware()
{
return $this->routeMiddleware;
}

/**
* Get the Laravel application instance.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Foundation/Http/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public function testGetMiddlewareGroups()
$this->assertEquals([], $kernel->getMiddlewareGroups());
}

public function testGetRouteMiddleware()
{
$kernel = new Kernel($this->getApplication(), $this->getRouter());

$this->assertEquals([], $kernel->getRouteMiddleware());
}

/**
* @return \Illuminate\Contracts\Foundation\Application
*/
Expand Down

0 comments on commit 5e8515d

Please sign in to comment.