From 4153a4fb21996a721bae6b3efe3a861de1c5c48e Mon Sep 17 00:00:00 2001 From: Divine Niiquaye Ibok Date: Mon, 10 Oct 2022 23:26:38 +0000 Subject: [PATCH] Fixed prefix group merging issue in the route collection's class --- src/RouteCollection.php | 2 +- tests/RouteCollectionTest.php | 28 +++++++++++----------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/RouteCollection.php b/src/RouteCollection.php index cbed238..25749d6 100644 --- a/src/RouteCollection.php +++ b/src/RouteCollection.php @@ -225,7 +225,7 @@ public function populate(self $collection, bool $asGroup = false) $this->add($route['path'], [], $route['handler']); $this->routes[$this->defaultIndex] = \array_merge_recursive( $this->routes[$this->defaultIndex], - \array_diff_key($route, ['path' => null, 'handler' => null]) + \array_diff_key($route, ['path' => null, 'handler' => null, 'prefix' => null]) ); } $this->asRoute = $asRoute; diff --git a/tests/RouteCollectionTest.php b/tests/RouteCollectionTest.php index 0151713..ada26ce 100644 --- a/tests/RouteCollectionTest.php +++ b/tests/RouteCollectionTest.php @@ -660,6 +660,16 @@ 'web' => true, ], ], + [ + 'handler' => 'Home::ping', + 'prefix' => '/api/ping', + 'path' => '/api/ping', + 'methods' => [ + 'GET' => true, + 'HEAD' => true, + ], + 'name' => 'api.ping', + ], [ 'handler' => 'Home::createProduct', 'prefix' => '/api/v1/product/create', @@ -692,10 +702,7 @@ ], [ 'handler' => 'Home::indexApi', - 'prefix' => [ - '/api', - null, - ], + 'prefix' => '/api', 'path' => '/api/', 'methods' => [ 'GET' => true, @@ -703,19 +710,6 @@ ], 'name' => 'api.GET_HEAD_api_', ], - [ - 'handler' => 'Home::ping', - 'prefix' => [ - '/api/ping', - '/ping', - ], - 'path' => '/api/ping', - 'methods' => [ - 'GET' => true, - 'HEAD' => true, - ], - 'name' => 'api.ping', - ], [ 'handler' => 'Home::productUpdate', 'prefix' => '/api/v1/product/update',