Skip to content

Commit

Permalink
Merge pull request #8040 from kenjis/fix-spark-routes-bug
Browse files Browse the repository at this point in the history
fix: `spark routes` may show incorrect route names
  • Loading branch information
kenjis authored Oct 16, 2023
2 parents 431748b + 19cdaf2 commit 21132d4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Router/DefinedRouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 41 additions & 0 deletions tests/system/Router/DefinedRouteCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down

0 comments on commit 21132d4

Please sign in to comment.