Skip to content

Commit e4f94e6

Browse files
tcochnicolas-grekas
authored andcommitted
[Routing] Add test to validate that default value is allowed to not match requirement
1 parent b51fb6b commit e4f94e6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Tests/Matcher/UrlMatcherTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,30 @@ public function testUtf8VarName()
982982
$this->assertEquals(['_route' => 'foo', 'bär' => 'baz', 'bäz' => 'foo'], $matcher->match('/foo/baz'));
983983
}
984984

985+
public function testParameterWithRequirementWithDefault()
986+
{
987+
$collection = new RouteCollection();
988+
989+
$route = new Route('/test/{foo}', ['foo' => 'foo-'], ['foo' => '\w+']);
990+
$collection->add('test', $route);
991+
992+
$matcher = $this->getUrlMatcher($collection);
993+
994+
$result = $matcher->match('/test/foo');
995+
$this->assertSame('test', $result['_route']);
996+
$this->assertSame('foo', $result['foo']);
997+
998+
try {
999+
$matcher->match('/test/foo-');
1000+
} catch (ResourceNotFoundException $e) {
1001+
$this->assertStringContainsString('No routes found', $e->getMessage());
1002+
}
1003+
1004+
$result = $matcher->match('/test');
1005+
$this->assertSame('test', $result['_route']);
1006+
$this->assertSame('foo-', $result['foo']);
1007+
}
1008+
9851009
protected function getUrlMatcher(RouteCollection $routes, ?RequestContext $context = null)
9861010
{
9871011
return new UrlMatcher($routes, $context ?? new RequestContext());

0 commit comments

Comments
 (0)