Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spark routes may show incorrect route names #8040

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading