Skip to content

Commit 5494772

Browse files
committed
test(Router): test non-default redirect status code and clean up comment
1 parent 33ff382 commit 5494772

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎system/Router/Router.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ protected function checkRoutes(string $uri): bool
477477
unset($matched);
478478
}
479479

480-
// Is this route supposed to redirect to another?
481480
if ($this->collection->isRedirect($matchedKey)) {
482481
// replacing matched route groups with references: post/([0-9]+) -> post/$1
483482
$redirectTo = preg_replace_callback('/(\([^\(]+\))/', static function (): string {

‎tests/system/Router/RouterTest.php‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,27 +949,28 @@ public function testRedirectRoute(
949949
string $url,
950950
string $expectedPath,
951951
string $alias,
952+
int $status = 302,
952953
): void {
953954
$collection = clone $this->collection;
954955
$collection->resetRoutes();
955956

956957
$collection->get($route, 'Controller::method', ['as' => $alias]);
957-
$collection->addRedirect($redirectFrom, $redirectTo);
958+
$collection->addRedirect($redirectFrom, $redirectTo, $status);
958959

959960
$this->expectException(RedirectException::class);
960961
$this->expectExceptionMessage($expectedPath);
961-
$this->expectExceptionCode(302);
962+
$this->expectExceptionCode($status);
962963

963964
$router = new Router($collection, $this->request);
964965
$router->handle($url);
965966
}
966967

967968
/**
968-
* @return iterable<int, array{string, string, string, string, string, string}>
969+
* @return iterable<int, array{string, string, string, string, string, string, 6?: int}>
969970
*/
970971
public static function provideRedirectRoute(): iterable
971972
{
972-
// [$route, $redirectFrom, $redirectTo, $url, $expectedPath, $alias]
973+
// [$route, $redirectFrom, $redirectTo, $url, $expectedPath, $alias, $status]
973974
return [
974975
['posts', 'articles', 'posts', '/articles', 'posts', 'alias'],
975976
['posts', 'articles', 'alias', '/articles', 'posts', 'alias'],
@@ -979,6 +980,7 @@ public static function provideRedirectRoute(): iterable
979980
['post/(:segment)/comment/(:any)', 'article/(:num)/(:any)', 'alias', '/article/1/2', 'post/1/comment/2', 'alias'],
980981
['posts', '{locale}/articles', 'posts', '/en/articles', 'posts', 'alias'],
981982
['{locale}/posts', '{locale}/articles', '{locale}/posts', '/en/articles', 'en/posts', 'alias'],
983+
['{locale}/posts', '{locale}/articles', '{locale}/posts', '/en/articles', 'en/posts', 'alias', 301],
982984
['{locale}/posts', '{locale}/articles', 'alias', '/en/articles', 'en/posts', 'alias'],
983985
['{locale}/post/(:num)', '{locale}/article/(:num)', '{locale}/post/$1', '/en/article/1', 'en/post/1', 'alias'],
984986
['{locale}/post/(:num)', '{locale}/article/(:num)', 'alias', '/en/article/1', 'en/post/1', 'alias'],

0 commit comments

Comments
 (0)