From 07648ae5ce79d09d1032818cb5af10cd5a5365e7 Mon Sep 17 00:00:00 2001 From: Roberto Aguilar Date: Fri, 26 Oct 2018 09:52:39 -0500 Subject: [PATCH] Create getter for the http middleware groups This getter allows to create tests for the route middleware groups, which is currently not possible because the property is protected. For example, if you want to ensure that the web group is using a middleware to track utm campaigns, with this getter you can write: ```php /** @test */ public function it_registers_the_track_utm_middleware_in_the_web_group() { $groups = resolve(\App\Http\Kernel::class)->getMiddlewareGroups(); $this->assertContains(\App\Http\Middleware\TrackUTM::class, $groups['web']); } ``` --- src/Illuminate/Foundation/Http/Kernel.php | 10 +++++++ tests/Foundation/Http/KernelTest.php | 35 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/Foundation/Http/KernelTest.php diff --git a/src/Illuminate/Foundation/Http/Kernel.php b/src/Illuminate/Foundation/Http/Kernel.php index f8460a550252..743001555ce5 100644 --- a/src/Illuminate/Foundation/Http/Kernel.php +++ b/src/Illuminate/Foundation/Http/Kernel.php @@ -335,4 +335,14 @@ public function getApplication() { return $this->app; } + + /** + * Get the application's route middleware groups. + * + * @return array + */ + public function getMiddlewareGroups() + { + return $this->middlewareGroups; + } } diff --git a/tests/Foundation/Http/KernelTest.php b/tests/Foundation/Http/KernelTest.php new file mode 100644 index 000000000000..e3f2d68203ff --- /dev/null +++ b/tests/Foundation/Http/KernelTest.php @@ -0,0 +1,35 @@ +getApplication(), $this->getRouter()); + + $this->assertEquals([], $kernel->getMiddlewareGroups()); + } + + /** + * @return \Illuminate\Foundation\Application + */ + protected function getApplication() + { + return new Application; + } + + /** + * @return \Illuminate\Routing\Router + */ + protected function getRouter() + { + return new Router(new Dispatcher); + } +}