diff --git a/src/Routing/NelmioAreaRoutesChecker.php b/src/Routing/NelmioAreaRoutesChecker.php index fdbed47..cf3cbf5 100644 --- a/src/Routing/NelmioAreaRoutesChecker.php +++ b/src/Routing/NelmioAreaRoutesChecker.php @@ -50,7 +50,7 @@ private function matchesByRouteName(string $routeName): bool foreach (array_keys($this->routesLocator->getProvidedServices()) as $area) { $routeCollection = $this->routesLocator->get($area); if (!$routeCollection instanceof RouteCollection) { - return false; + continue; } if (null !== $routeCollection->get($routeName)) { diff --git a/tests/Unit/Routing/NelmioAreaRoutesTest.php b/tests/Unit/Routing/NelmioAreaRoutesTest.php index 94480af..002601b 100644 --- a/tests/Unit/Routing/NelmioAreaRoutesTest.php +++ b/tests/Unit/Routing/NelmioAreaRoutesTest.php @@ -103,8 +103,9 @@ public function testReturnsTrueWhenFoundInSecondArea(): void self::assertTrue($checker->isApiRoute($request)); } - public function testNonRouteCollectionServiceCausesFalse(): void + public function testNonRouteCollectionServiceOnlySkipsItsOwnArea(): void { + // Arrange — order matters: the unusable entry must come before the area holding the route. $notARouteCollection = static fn () => (object) ['not' => 'a route collection']; $collection = new RouteCollection(); @@ -121,6 +122,24 @@ public function testNonRouteCollectionServiceCausesFalse(): void $request = new Request(); $request->attributes->set('_route', 'would_match'); + // Act & Assert + self::assertTrue($checker->isApiRoute($request)); + } + + public function testUnusableAreasAloneStillReturnFalse(): void + { + // Arrange + /** @var ServiceLocator $locator */ + $locator = new ServiceLocator([ + 'not_a_route_collection' => static fn () => (object) ['not' => 'a route collection'], + ]); + + $checker = new NelmioAreaRoutesChecker($locator); + + $request = new Request(); + $request->attributes->set('_route', 'anything'); + + // Act & Assert self::assertFalse($checker->isApiRoute($request)); }