Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Routing/NelmioAreaRoutesChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
21 changes: 20 additions & 1 deletion tests/Unit/Routing/NelmioAreaRoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<RouteCollection> $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));
}

Expand Down
Loading