Skip to content

Commit efdfe8d

Browse files
committed
feat: Handle localized routes
1 parent 78e5bd6 commit efdfe8d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<server name="SHELL_VERBOSITY" value="-1" />
1616
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
1717
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
18-
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=0&amp;max[self]=0" />
18+
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=1&amp;max[self]=0" />
1919
</php>
2020

2121
<testsuites>

src/Analysis/Analyser.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ public function run(array $routesToIgnore): AnalysisResult
2525
{
2626
$routesToIgnore = array_merge($this->getDefaultRoutesToIgnore(), $routesToIgnore);
2727

28-
$routes = $this->filterRoutes(array_keys($this->router->getRouteCollection()->all()), $routesToIgnore);
28+
$routeNames = [];
29+
foreach ($this->router->getRouteCollection()->all() as $routeName => $route) {
30+
$routeNames[] = $route->getDefaults()['_canonical_route'] ?? $routeName;
31+
}
32+
$routeNames = array_unique($routeNames);
33+
34+
$routes = $this->filterRoutes($routeNames, $routesToIgnore);
2935
$testedRoutes = $this->filterRoutes(array_unique(array_keys($this->routeStorage->getRoutes())), $routesToIgnore);
3036

3137
$successfullyTestedRoutes = array_keys(array_filter($this->routeStorage->getRoutes(), static function (array $responseCodes): bool {

tests/Analysis/AnalyserTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\MockObject\MockObject;
88
use PHPUnit\Framework\TestCase;
9+
use Symfony\Component\Routing\Loader\Configurator\Traits\LocalizedRouteTrait;
910
use Symfony\Component\Routing\Route;
1011
use Symfony\Component\Routing\RouteCollection;
1112
use Symfony\Component\Routing\RouterInterface;
@@ -15,6 +16,8 @@
1516

1617
final class AnalyserTest extends TestCase
1718
{
19+
use LocalizedRouteTrait;
20+
1821
public function testAnalysis(): void
1922
{
2023
$routeCollection = new RouteCollection();
@@ -24,26 +27,32 @@ public function testAnalysis(): void
2427
$routeCollection->add('ignored_route1', new Route('/ignored_route1'));
2528
$routeCollection->add('_wdt', new Route('/_wdt'));
2629
$routeCollection->add('_wdt_stylesheet', new Route('/_wdt_stylesheet'));
30+
$this->createLocalizedRoute($routeCollection, 'localized_route_simple_path', '/localized');
31+
$this->createLocalizedRoute($routeCollection, 'localized_route_multiple_paths', [
32+
'en' => '/en/localized',
33+
'fr' => '/fr/localized',
34+
'de' => '/de/localized',
35+
]);
2736

2837
/** @var RouterInterface&MockObject $router */
2938
$router = $this->createMock(RouterInterface::class);
3039
$router->expects($this->once())
3140
->method('getRouteCollection')
3241
->willReturn($routeCollection);
3342

34-
/** @®ar RouteStorageInterface&MockObject $routeStorage */
43+
/** @var RouteStorageInterface&MockObject $routeStorage */
3544
$routeStorage = $this->createMock(RouteStorageInterface::class);
3645
$routeStorage->expects($this->exactly(2))
3746
->method('getRoutes')
3847
->willReturn(['route1' => [200], 'route2' => [404]]);
3948

4049
$analyser = new Analyser($router, $routeStorage);
4150

42-
$result = $analyser->run(['ignored_.*']);
51+
$result = $analyser->run(routesToIgnore: ['ignored_.*']);
4352

4453
$this->assertInstanceOf(AnalysisResult::class, $result);
4554
$this->assertSame(['route1', 'route2'], $result->getTestedRoutes());
46-
$this->assertSame(['route3'], $result->getNotTestedRoutes());
55+
$this->assertSame(['route3', 'localized_route_simple_path', 'localized_route_multiple_paths'], $result->getNotTestedRoutes());
4756
$this->assertSame(['route1'], $result->getSuccessfullyTestedRoutes());
4857
$this->assertSame(['route2'], $result->getNotSuccessfullyTestedRoutes());
4958
}

0 commit comments

Comments
 (0)