Skip to content

Commit 21132d4

Browse files
authored
Merge pull request #8040 from kenjis/fix-spark-routes-bug
fix: `spark routes` may show incorrect route names
2 parents 431748b + 19cdaf2 commit 21132d4

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

system/Router/DefinedRouteCollector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function collect(): Generator
5757
$handler = $view ? '(View) ' . $view : '(Closure)';
5858
}
5959

60-
$routeName = $this->routeCollection->getRoutesOptions($route)['as'] ?? $route;
60+
$routeName = $this->routeCollection->getRoutesOptions($route, $method)['as'] ?? $route;
6161

6262
yield [
6363
'method' => $method,

tests/system/Router/DefinedRouteCollectorTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,45 @@ public function testCollect()
8787
];
8888
$this->assertSame($expected, $definedRoutes);
8989
}
90+
91+
/**
92+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8039
93+
*/
94+
public function testCollectSameFromWithDifferentVerb()
95+
{
96+
$routes = $this->createRouteCollection();
97+
$routes->get('login', 'AuthController::showLogin', ['as' => 'loginShow']);
98+
$routes->post('login', 'AuthController::login', ['as' => 'login']);
99+
$routes->get('logout', 'AuthController::logout', ['as' => 'logout']);
100+
101+
$collector = new DefinedRouteCollector($routes);
102+
103+
$definedRoutes = [];
104+
105+
foreach ($collector->collect() as $route) {
106+
$definedRoutes[] = $route;
107+
}
108+
109+
$expected = [
110+
[
111+
'method' => 'get',
112+
'route' => 'login',
113+
'name' => 'loginShow',
114+
'handler' => '\\App\\Controllers\\AuthController::showLogin',
115+
],
116+
[
117+
'method' => 'get',
118+
'route' => 'logout',
119+
'name' => 'logout',
120+
'handler' => '\\App\\Controllers\\AuthController::logout',
121+
],
122+
[
123+
'method' => 'post',
124+
'route' => 'login',
125+
'name' => 'login',
126+
'handler' => '\\App\\Controllers\\AuthController::login',
127+
],
128+
];
129+
$this->assertSame($expected, $definedRoutes);
130+
}
90131
}

user_guide_src/source/changelogs/v4.4.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Bugs Fixed
4646
production mode or to display backtrace in json when an exception occurred.
4747
- **Forge:** Fixed a bug where adding a Primary Key to an existing table was
4848
ignored if there were no other Keys added too.
49+
- **Routing:** Fixed a bug that ``spark routes`` may show incorrect route names.
4950

5051
See the repo's
5152
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)