From 8987b3eac84e5d3a40411adb00dd531994851690 Mon Sep 17 00:00:00 2001 From: Mathias Grimm Date: Tue, 31 Dec 2024 15:45:43 -0300 Subject: [PATCH] Adding tests for Overlapping Routes --- tests/Routing/RouteCollectionTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Routing/RouteCollectionTest.php b/tests/Routing/RouteCollectionTest.php index 1c2517b0f92a..c299cc4b0fdb 100644 --- a/tests/Routing/RouteCollectionTest.php +++ b/tests/Routing/RouteCollectionTest.php @@ -325,4 +325,20 @@ public function testToSymfonyRouteCollection() $this->assertInstanceOf("\Symfony\Component\Routing\RouteCollection", $this->routeCollection->toSymfonyRouteCollection()); } + + public function testOverlappingRoutesMatchesFirstRoute() + { + $this->routeCollection->add( + new Route('GET', 'users/{id}/{other}', ['uses' => 'UsersController@other', 'as' => 'first']) + ); + + $this->routeCollection->add( + new Route('GET', 'users/{id}/show', ['uses' => 'UsersController@show', 'as' => 'second']) + ); + + $request = Request::create('users/1/show', 'GET'); + + $this->assertCount(2, $this->routeCollection->getRoutes()); + $this->assertEquals('first', $this->routeCollection->match($request)->getName()); + } }