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,42 @@ 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+ * @group legacy
56+ *
57+ * @param string $routeName
58+ * @param string $path
59+ * @param string[] $methods
60+ */
61+ public function testLoadRoutingLegacy ($ routeName , $ path , array $ methods )
62+ {
63+ if (!class_exists (XmlFileLoader::class)) {
64+ $ this ->markTestSkipped ('XML routing files are not supported on Symfony 8. ' );
65+ }
66+
3067 $ locator = new FileLocator ();
3168 $ loader = new XmlFileLoader ($ locator );
3269
@@ -52,7 +89,7 @@ public function testLoadRouting($routeName, $path, array $methods)
5289 /**
5390 * @return iterable<array{string, string, string[]}>
5491 */
55- public function loadRoutingProvider (): iterable
92+ public static function loadRoutingProvider (): iterable
5693 {
5794 return [
5895 ['fos_user_change_password ' , '/change-password ' , ['GET ' , 'POST ' ]],
@@ -75,4 +112,37 @@ public function loadRoutingProvider(): iterable
75112 ['fos_user_security_logout ' , '/logout ' , ['GET ' , 'POST ' ]],
76113 ];
77114 }
115+
116+ /**
117+ * @dataProvider provideRouteFiles
118+ *
119+ * @group legacy
120+ */
121+ public function testLegacyFileConsistency (string $ filename ): void
122+ {
123+ if (!class_exists (XmlFileLoader::class)) {
124+ $ this ->markTestSkipped ('XML routing files are not supported on Symfony 8. ' );
125+ }
126+
127+ $ locator = new FileLocator ();
128+
129+ $ phpLoader = new PhpFileLoader ($ locator );
130+ $ xmlLoader = new XmlFileLoader ($ locator );
131+
132+ $ phpCollection = $ phpLoader ->load (__DIR__ .\sprintf ('/../../src/Resources/config/routing/%s.php ' , $ filename ));
133+ $ xmlCollection = $ xmlLoader ->load (__DIR__ .\sprintf ('/../../src/Resources/config/routing/%s.xml ' , $ filename ));
134+
135+ $ this ->assertEquals ($ phpCollection ->all (), $ xmlCollection ->all ());
136+ }
137+
138+ /**
139+ * @return iterable<array{string}>
140+ */
141+ public static function provideRouteFiles (): iterable
142+ {
143+ yield ['profile ' ];
144+ yield ['registration ' ];
145+ yield ['resetting ' ];
146+ yield ['security ' ];
147+ }
78148}
0 commit comments