diff --git a/src/Routing/Router.php b/src/Routing/Router.php index dc91c3b0e..c6418be5e 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -663,4 +663,16 @@ public function getInspector() return $this->inspector ?: $this->inspector = new ControllerInspector; } + public function getRoutes() + { + $routes = parent::getRoutes(); + + foreach($this->api as $apiRoutes) { + foreach($apiRoutes->getRoutes() as $apiRoute) { + $routes->add($apiRoute); + } + } + + return $routes; + } } diff --git a/tests/RoutingRouterTest.php b/tests/RoutingRouterTest.php index 6e2ee5fad..116ad537a 100644 --- a/tests/RoutingRouterTest.php +++ b/tests/RoutingRouterTest.php @@ -429,5 +429,11 @@ public function testRouterDefaultsToDefaultVersionCollectionWhenNoAcceptHeader() $this->assertEquals('{"message":"baz"}', $this->router->dispatch($request)->getContent()); } + public function testRouterReturnsCorrectRoutesForArtisanCommand() + { + $this->router->api(['version' => 'v1'], function() { $this->router->get('foo', function() { return 'bar'; }); }); + $this->router->get('bar', function() { return 'baz'; }); + $this->assertCount(2, $this->router->getRoutes()); + } }