From 5af603cb217c233c4fe706239a9310f89c2ceeb5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 15:46:43 +0900 Subject: [PATCH 1/3] test: add test --- .../Router/DefinedRouteCollectorTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/system/Router/DefinedRouteCollectorTest.php b/tests/system/Router/DefinedRouteCollectorTest.php index ba74cec1a86a..976d74268a35 100644 --- a/tests/system/Router/DefinedRouteCollectorTest.php +++ b/tests/system/Router/DefinedRouteCollectorTest.php @@ -87,4 +87,45 @@ public function testCollect() ]; $this->assertSame($expected, $definedRoutes); } + + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/8039 + */ + public function testCollectSameFromWithDifferentVerb() + { + $routes = $this->createRouteCollection(); + $routes->get('login', 'AuthController::showLogin', ['as' => 'loginShow']); + $routes->post('login', 'AuthController::login', ['as' => 'login']); + $routes->get('logout', 'AuthController::logout', ['as' => 'logout']); + + $collector = new DefinedRouteCollector($routes); + + $definedRoutes = []; + + foreach ($collector->collect() as $route) { + $definedRoutes[] = $route; + } + + $expected = [ + [ + 'method' => 'get', + 'route' => 'login', + 'name' => 'loginShow', + 'handler' => '\\App\\Controllers\\AuthController::showLogin', + ], + [ + 'method' => 'get', + 'route' => 'logout', + 'name' => 'logout', + 'handler' => '\\App\\Controllers\\AuthController::logout', + ], + [ + 'method' => 'post', + 'route' => 'login', + 'name' => 'login', + 'handler' => '\\App\\Controllers\\AuthController::login', + ], + ]; + $this->assertSame($expected, $definedRoutes); + } } From 68f8218b113f9648a43ff5298c6ce73518c54bc8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 15:47:00 +0900 Subject: [PATCH 2/3] fix: DefinedRouteCollector returns incorrect route data --- system/Router/DefinedRouteCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Router/DefinedRouteCollector.php b/system/Router/DefinedRouteCollector.php index 2b317d4cbc2a..f8e245d19723 100644 --- a/system/Router/DefinedRouteCollector.php +++ b/system/Router/DefinedRouteCollector.php @@ -57,7 +57,7 @@ public function collect(): Generator $handler = $view ? '(View) ' . $view : '(Closure)'; } - $routeName = $this->routeCollection->getRoutesOptions($route)['as'] ?? $route; + $routeName = $this->routeCollection->getRoutesOptions($route, $method)['as'] ?? $route; yield [ 'method' => $method, From 19cdaf2e4e713a917bcbc311df29d3b25c5dc6d5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 15:51:29 +0900 Subject: [PATCH 3/3] docs: add changelog --- user_guide_src/source/changelogs/v4.4.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelogs/v4.4.2.rst b/user_guide_src/source/changelogs/v4.4.2.rst index beb5790fc8c1..bacfdf2a2e97 100644 --- a/user_guide_src/source/changelogs/v4.4.2.rst +++ b/user_guide_src/source/changelogs/v4.4.2.rst @@ -46,6 +46,7 @@ Bugs Fixed production mode or to display backtrace in json when an exception occurred. - **Forge:** Fixed a bug where adding a Primary Key to an existing table was ignored if there were no other Keys added too. +- **Routing:** Fixed a bug that ``spark routes`` may show incorrect route names. See the repo's `CHANGELOG.md `_