diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 59d1fd8..229e85f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,7 +15,7 @@ - + diff --git a/src/Analysis/Analyser.php b/src/Analysis/Analyser.php index 40fb99e..9a16247 100644 --- a/src/Analysis/Analyser.php +++ b/src/Analysis/Analyser.php @@ -25,7 +25,13 @@ public function run(array $routesToIgnore): AnalysisResult { $routesToIgnore = array_merge($this->getDefaultRoutesToIgnore(), $routesToIgnore); - $routes = $this->filterRoutes(array_keys($this->router->getRouteCollection()->all()), $routesToIgnore); + $routeNames = []; + foreach ($this->router->getRouteCollection()->all() as $routeName => $route) { + $routeNames[] = $route->getDefaults()['_canonical_route'] ?? $routeName; + } + $routeNames = array_unique($routeNames); + + $routes = $this->filterRoutes($routeNames, $routesToIgnore); $testedRoutes = $this->filterRoutes(array_unique(array_keys($this->routeStorage->getRoutes())), $routesToIgnore); $successfullyTestedRoutes = array_keys(array_filter($this->routeStorage->getRoutes(), static function (array $responseCodes): bool { diff --git a/tests/Analysis/AnalyserTest.php b/tests/Analysis/AnalyserTest.php index 418c54b..f59a102 100644 --- a/tests/Analysis/AnalyserTest.php +++ b/tests/Analysis/AnalyserTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Symfony\Component\Routing\Loader\Configurator\Traits\LocalizedRouteTrait; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouterInterface; @@ -15,6 +16,8 @@ final class AnalyserTest extends TestCase { + use LocalizedRouteTrait; + public function testAnalysis(): void { $routeCollection = new RouteCollection(); @@ -24,6 +27,12 @@ public function testAnalysis(): void $routeCollection->add('ignored_route1', new Route('/ignored_route1')); $routeCollection->add('_wdt', new Route('/_wdt')); $routeCollection->add('_wdt_stylesheet', new Route('/_wdt_stylesheet')); + $this->createLocalizedRoute($routeCollection, 'localized_route_simple_path', '/localized'); + $this->createLocalizedRoute($routeCollection, 'localized_route_multiple_paths', [ + 'en' => '/en/localized', + 'fr' => '/fr/localized', + 'de' => '/de/localized', + ]); /** @var RouterInterface&MockObject $router */ $router = $this->createMock(RouterInterface::class); @@ -31,7 +40,7 @@ public function testAnalysis(): void ->method('getRouteCollection') ->willReturn($routeCollection); - /** @®ar RouteStorageInterface&MockObject $routeStorage */ + /** @var RouteStorageInterface&MockObject $routeStorage */ $routeStorage = $this->createMock(RouteStorageInterface::class); $routeStorage->expects($this->exactly(2)) ->method('getRoutes') @@ -39,11 +48,11 @@ public function testAnalysis(): void $analyser = new Analyser($router, $routeStorage); - $result = $analyser->run(['ignored_.*']); + $result = $analyser->run(routesToIgnore: ['ignored_.*']); $this->assertInstanceOf(AnalysisResult::class, $result); $this->assertSame(['route1', 'route2'], $result->getTestedRoutes()); - $this->assertSame(['route3'], $result->getNotTestedRoutes()); + $this->assertSame(['route3', 'localized_route_simple_path', 'localized_route_multiple_paths'], $result->getNotTestedRoutes()); $this->assertSame(['route1'], $result->getSuccessfullyTestedRoutes()); $this->assertSame(['route2'], $result->getNotSuccessfullyTestedRoutes()); }