Skip to content

Commit a0d4dbb

Browse files
committed
test(Router): cover 9-placeholder boundary and out-of-range back-references
1 parent e83f07b commit a0d4dbb

1 file changed

Lines changed: 43 additions & 8 deletions

File tree

‎tests/system/Router/RouterTest.php‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,24 +1009,59 @@ public function testRoutePlaceholderAnyWithMultipleSegmentsParamTrue(): void
10091009
$this->assertSame(['123/456'], $router->params());
10101010
}
10111011

1012-
public function testMultipleSegmentsParamTrueWithTenPlaceholders(): void
1013-
{
1012+
/**
1013+
* @param list<string> $expectedParams
1014+
*/
1015+
#[DataProvider('provideMultipleSegmentsParamTruePlaceholders')]
1016+
public function testMultipleSegmentsParamTrueWithManyPlaceholders(
1017+
string $route,
1018+
string $handler,
1019+
string $uri,
1020+
array $expectedParams,
1021+
): void {
10141022
$routingConfig = new Routing();
10151023
$routingConfig->multipleSegmentsOneParam = true;
10161024
Factories::injectMock('config', Routing::class, $routingConfig);
10171025

10181026
$this->createRouteCollection($routingConfig);
1019-
$this->collection->get(
1020-
'(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)',
1021-
'Catalog::lookup/$1/$2/$3/$4/$5/$6/$7/$8/$9/$10',
1022-
);
1027+
$this->collection->get($route, $handler);
10231028
$router = new Router($this->collection, $this->request);
10241029

1025-
$router->handle('a/b/c/d/e/f/g/h/i/j');
1030+
$router->handle($uri);
10261031

10271032
$this->assertSame('\Catalog', $router->controllerName());
10281033
$this->assertSame('lookup', $router->methodName());
1029-
$this->assertSame(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], $router->params());
1034+
$this->assertSame($expectedParams, $router->params());
1035+
}
1036+
1037+
/**
1038+
* @return iterable<string, array{string, string, string, list<string>}>
1039+
*/
1040+
public static function provideMultipleSegmentsParamTruePlaceholders(): iterable
1041+
{
1042+
$nineSegments = implode('/', array_fill(0, 9, '(:segment)'));
1043+
$tenSegments = implode('/', array_fill(0, 10, '(:segment)'));
1044+
1045+
yield 'nine placeholders (boundary)' => [
1046+
$nineSegments,
1047+
'Catalog::lookup/$1/$2/$3/$4/$5/$6/$7/$8/$9',
1048+
'a/b/c/d/e/f/g/h/i',
1049+
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'],
1050+
];
1051+
1052+
yield 'ten placeholders' => [
1053+
$tenSegments,
1054+
'Catalog::lookup/$1/$2/$3/$4/$5/$6/$7/$8/$9/$10',
1055+
'a/b/c/d/e/f/g/h/i/j',
1056+
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],
1057+
];
1058+
1059+
yield 'out-of-range reference resolves to empty string' => [
1060+
$tenSegments,
1061+
'Catalog::lookup/$1/$2/$3/$4/$5/$6/$7/$8/$9/$10/$11',
1062+
'a/b/c/d/e/f/g/h/i/j',
1063+
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', ''],
1064+
];
10301065
}
10311066

10321067
public function testLogsRouteAttributeInstantiationFailureWithContext(): void

0 commit comments

Comments
 (0)