1212namespace Symfony \Component \DependencyInjection \Tests ;
1313
1414use PHPUnit \Framework \Attributes \DataProvider ;
15+ use PHPUnit \Framework \Attributes \Group ;
16+ use PHPUnit \Framework \Attributes \IgnoreDeprecations ;
1517use PHPUnit \Framework \TestCase ;
1618use Symfony \Component \Config \FileLocator ;
1719use Symfony \Component \DependencyInjection \ContainerBuilder ;
20+ use Symfony \Component \DependencyInjection \Dumper \XmlDumper ;
21+ use Symfony \Component \DependencyInjection \Dumper \YamlDumper ;
22+ use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
23+ use Symfony \Component \DependencyInjection \Loader \YamlFileLoader ;
1824
1925class CrossCheckTest extends TestCase
2026{
@@ -28,25 +34,26 @@ public static function setUpBeforeClass(): void
2834 require_once self ::$ fixturesPath .'/includes/foo.php ' ;
2935 }
3036
31- #[DataProvider('crossCheckLoadersDumpers ' )]
32- public function testCrossCheck ($ fixture , $ type )
37+ #[IgnoreDeprecations]
38+ #[Group('legacy ' )]
39+ #[DataProvider('crossCheckXmlLoadersDumpers ' )]
40+ public function testXmlCrossCheck ($ fixture )
3341 {
34- $ loaderClass = 'Symfony \\Component \\DependencyInjection \\Loader \\' .ucfirst ($ type ).'FileLoader ' ;
35- $ dumperClass = 'Symfony \\Component \\DependencyInjection \\Dumper \\' .ucfirst ($ type ).'Dumper ' ;
42+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
3643
3744 $ tmp = tempnam (sys_get_temp_dir (), 'sf ' );
3845
39- copy (self ::$ fixturesPath .'/ ' . $ type . ' / ' .$ fixture , $ tmp );
46+ copy (self ::$ fixturesPath .'/xml / ' .$ fixture , $ tmp );
4047
4148 $ container1 = new ContainerBuilder ();
42- $ loader1 = new $ loaderClass ($ container1 , new FileLocator ());
49+ $ loader1 = new XmlFileLoader ($ container1 , new FileLocator ());
4350 $ loader1 ->load ($ tmp );
4451
45- $ dumper = new $ dumperClass ($ container1 );
52+ $ dumper = new XmlDumper ($ container1 );
4653 file_put_contents ($ tmp , $ dumper ->dump ());
4754
4855 $ container2 = new ContainerBuilder ();
49- $ loader2 = new $ loaderClass ($ container2 , new FileLocator ());
56+ $ loader2 = new XmlFileLoader ($ container2 , new FileLocator ());
5057 $ loader2 ->load ($ tmp );
5158
5259 unlink ($ tmp );
@@ -70,19 +77,64 @@ public function testCrossCheck($fixture, $type)
7077 $ this ->assertEquals ($ services1 , $ services2 , 'Iterator on the containers returns the same services ' );
7178 }
7279
73- public static function crossCheckLoadersDumpers ()
80+ #[DataProvider('crossCheckYamlLoadersDumpers ' )]
81+ public function testYamlCrossCheck ($ fixture )
82+ {
83+ $ tmp = tempnam (sys_get_temp_dir (), 'sf ' );
84+
85+ copy (self ::$ fixturesPath .'/yaml/ ' .$ fixture , $ tmp );
86+
87+ $ container1 = new ContainerBuilder ();
88+ $ loader1 = new YamlFileLoader ($ container1 , new FileLocator ());
89+ $ loader1 ->load ($ tmp );
90+
91+ $ dumper = new YamlDumper ($ container1 );
92+ file_put_contents ($ tmp , $ dumper ->dump ());
93+
94+ $ container2 = new ContainerBuilder ();
95+ $ loader2 = new YamlFileLoader ($ container2 , new FileLocator ());
96+ $ loader2 ->load ($ tmp );
97+
98+ unlink ($ tmp );
99+
100+ $ this ->assertEquals ($ container2 ->getAliases (), $ container1 ->getAliases (), 'loading a dump from a previously loaded container returns the same container ' );
101+ $ this ->assertEquals ($ container2 ->getDefinitions (), $ container1 ->getDefinitions (), 'loading a dump from a previously loaded container returns the same container ' );
102+ $ this ->assertEquals ($ container2 ->getParameterBag ()->all (), $ container1 ->getParameterBag ()->all (), '->getParameterBag() returns the same value for both containers ' );
103+ $ this ->assertEquals (serialize ($ container2 ), serialize ($ container1 ), 'loading a dump from a previously loaded container returns the same container ' );
104+
105+ $ services1 = [];
106+ foreach ($ container1 as $ id => $ service ) {
107+ $ services1 [$ id ] = serialize ($ service );
108+ }
109+ $ services2 = [];
110+ foreach ($ container2 as $ id => $ service ) {
111+ $ services2 [$ id ] = serialize ($ service );
112+ }
113+
114+ unset($ services1 ['service_container ' ], $ services2 ['service_container ' ]);
115+
116+ $ this ->assertEquals ($ services2 , $ services1 , 'Iterator on the containers returns the same services ' );
117+ }
118+
119+ public static function crossCheckXmlLoadersDumpers ()
120+ {
121+ return [
122+ ['services1.xml ' ],
123+ ['services2.xml ' ],
124+ ['services6.xml ' ],
125+ ['services8.xml ' ],
126+ ['services9.xml ' ],
127+ ];
128+ }
129+
130+ public static function crossCheckYamlLoadersDumpers ()
74131 {
75132 return [
76- ['services1.xml ' , 'xml ' ],
77- ['services2.xml ' , 'xml ' ],
78- ['services6.xml ' , 'xml ' ],
79- ['services8.xml ' , 'xml ' ],
80- ['services9.xml ' , 'xml ' ],
81- ['services1.yml ' , 'yaml ' ],
82- ['services2.yml ' , 'yaml ' ],
83- ['services6.yml ' , 'yaml ' ],
84- ['services8.yml ' , 'yaml ' ],
85- ['services9.yml ' , 'yaml ' ],
133+ ['services1.yml ' ],
134+ ['services2.yml ' ],
135+ ['services6.yml ' ],
136+ ['services8.yml ' ],
137+ ['services9.yml ' ],
86138 ];
87139 }
88140}
0 commit comments