From 9a5c31e43a56123a34125e2226b7f6ad72f11ba0 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 10 May 2017 21:53:22 -0400 Subject: [PATCH] Add getRouteCollection() This method will be used by the new hooks to create the initial builder that is passed to the application's routing hook. --- src/Routing/Router.php | 10 ++++++++++ tests/TestCase/Routing/RouterTest.php | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 7db2489eed3..46cca8db033 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -1059,6 +1059,16 @@ public static function routes() return static::$_collection->routes(); } + /** + * Get the RouteCollection inside the Router + * + * @return \Cake\Routing\RouteCollection + */ + public static function getRouteCollection() + { + return static::$_collection; + } + /** * Get a MiddlewareQueue of middleware that matches the provided path. * diff --git a/tests/TestCase/Routing/RouterTest.php b/tests/TestCase/Routing/RouterTest.php index b219fa423a4..812c0694d79 100644 --- a/tests/TestCase/Routing/RouterTest.php +++ b/tests/TestCase/Routing/RouterTest.php @@ -19,6 +19,7 @@ use Cake\Http\MiddlewareQueue; use Cake\Http\ServerRequest; use Cake\Http\ServerRequestFactory; +use Cake\Routing\RouteCollection; use Cake\Routing\Router; use Cake\Routing\Route\Route; use Cake\TestSuite\TestCase; @@ -3363,6 +3364,18 @@ public function testGetMatchingMiddleware() $this->assertCount(1, $result); } + /** + * Test getting the route collection + * + * @return void + */ + public function testGetRouteCollection() + { + $collection = Router::getRouteCollection(); + $this->assertInstanceOf(RouteCollection::class, $collection); + $this->assertCount(0, $collection->routes()); + } + /** * Connect some fallback routes for testing router behavior. *