1313
1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Component \Config \FileLocator ;
16+ use Symfony \Component \Routing \Loader \PhpFileLoader ;
1617use Symfony \Component \Routing \Loader \XmlFileLoader ;
1718use Symfony \Component \Routing \RouteCollection ;
1819
@@ -27,6 +28,43 @@ class RoutingTest extends TestCase
2728 */
2829 public function testLoadRouting ($ routeName , $ path , array $ methods )
2930 {
31+ $ locator = new FileLocator ();
32+ $ loader = new PhpFileLoader ($ locator );
33+
34+ $ collection = new RouteCollection ();
35+ $ collection ->addCollection ($ loader ->load (__DIR__ .'/../../src/Resources/config/routing/change_password.php ' ));
36+ $ subCollection = $ loader ->load (__DIR__ .'/../../src/Resources/config/routing/profile.php ' );
37+ $ subCollection ->addPrefix ('/profile ' );
38+ $ collection ->addCollection ($ subCollection );
39+ $ subCollection = $ loader ->load (__DIR__ .'/../../src/Resources/config/routing/registration.php ' );
40+ $ subCollection ->addPrefix ('/register ' );
41+ $ collection ->addCollection ($ subCollection );
42+ $ subCollection = $ loader ->load (__DIR__ .'/../../src/Resources/config/routing/resetting.php ' );
43+ $ subCollection ->addPrefix ('/resetting ' );
44+ $ collection ->addCollection ($ subCollection );
45+ $ collection ->addCollection ($ loader ->load (__DIR__ .'/../../src/Resources/config/routing/security.php ' ));
46+
47+ $ route = $ collection ->get ($ routeName );
48+ $ this ->assertNotNull ($ route , sprintf ('The route "%s" should exists ' , $ routeName ));
49+ $ this ->assertSame ($ path , $ route ->getPath ());
50+ $ this ->assertSame ($ methods , $ route ->getMethods ());
51+ }
52+
53+ /**
54+ * @dataProvider loadRoutingProvider
55+ *
56+ * @group legacy
57+ *
58+ * @param string $routeName
59+ * @param string $path
60+ * @param string[] $methods
61+ */
62+ public function testLoadRoutingLegacy ($ routeName , $ path , array $ methods )
63+ {
64+ if (!class_exists (XmlFileLoader::class)) {
65+ $ this ->markTestSkipped ('XML routing files are not supported on Symfony 8. ' );
66+ }
67+
3068 $ locator = new FileLocator ();
3169 $ loader = new XmlFileLoader ($ locator );
3270
@@ -52,7 +90,7 @@ public function testLoadRouting($routeName, $path, array $methods)
5290 /**
5391 * @return iterable<array{string, string, string[]}>
5492 */
55- public function loadRoutingProvider (): iterable
93+ public static function loadRoutingProvider (): iterable
5694 {
5795 return [
5896 ['fos_user_change_password ' , '/change-password ' , ['GET ' , 'POST ' ]],
@@ -75,4 +113,38 @@ public function loadRoutingProvider(): iterable
75113 ['fos_user_security_logout ' , '/logout ' , ['GET ' , 'POST ' ]],
76114 ];
77115 }
116+
117+ /**
118+ * @dataProvider provideRouteFiles
119+ *
120+ * @group legacy
121+ */
122+ public function testLegacyFileConsistency (string $ filename ): void
123+ {
124+ if (!class_exists (XmlFileLoader::class)) {
125+ $ this ->markTestSkipped ('XML routing files are not supported on Symfony 8. ' );
126+ }
127+
128+ $ locator = new FileLocator ();
129+
130+ $ phpLoader = new PhpFileLoader ($ locator );
131+ $ xmlLoader = new XmlFileLoader ($ locator );
132+
133+ $ phpCollection = $ phpLoader ->load (__DIR__ .\sprintf ('/../../src/Resources/config/routing/%s.php ' , $ filename ));
134+ $ xmlCollection = $ xmlLoader ->load (__DIR__ .\sprintf ('/../../src/Resources/config/routing/%s.xml ' , $ filename ));
135+
136+ $ this ->assertEquals ($ phpCollection ->all (), $ xmlCollection ->all ());
137+ }
138+
139+ /**
140+ * @return iterable<array{string}>
141+ */
142+ public static function provideRouteFiles (): iterable
143+ {
144+ yield ['profile ' ];
145+ yield ['registration ' ];
146+ yield ['resetting ' ];
147+ yield ['security ' ];
148+ }
78149}
150+ // @php-cs-fixer-ignore php_unit_strict We intentionally use a non-strict comparison to verify that loaded routes are equivalent in the consistency test.
0 commit comments