Skip to content
Open
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 phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=0&amp;max[self]=0" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=1&amp;max[self]=0" />
</php>

<testsuites>
Expand Down
8 changes: 7 additions & 1 deletion src/Analysis/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions tests/Analysis/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,8 @@

final class AnalyserTest extends TestCase
{
use LocalizedRouteTrait;

public function testAnalysis(): void
{
$routeCollection = new RouteCollection();
Expand All @@ -24,26 +27,32 @@ 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);
$router->expects($this->once())
->method('getRouteCollection')
->willReturn($routeCollection);

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

$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());
}
Expand Down