1212namespace Symfony \Bundle \FrameworkBundle \Tests \CacheWarmer ;
1313
1414use PHPUnit \Framework \Attributes \DataProvider ;
15+ use PHPUnit \Framework \Attributes \Group ;
16+ use PHPUnit \Framework \Attributes \IgnoreDeprecations ;
1517use Symfony \Bundle \FrameworkBundle \CacheWarmer \SerializerCacheWarmer ;
1618use Symfony \Bundle \FrameworkBundle \Tests \TestCase ;
1719use Symfony \Component \Cache \Adapter \NullAdapter ;
@@ -39,8 +41,26 @@ private function getArrayPool(string $file): PhpArrayAdapter
3941 return $ this ->arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
4042 }
4143
42- #[DataProvider('loaderProvider ' )]
43- public function testWarmUp (array $ loaders )
44+ #[DataProvider('yamlLoaderProvider ' )]
45+ public function testYamlWarmUp (array $ loaders )
46+ {
47+ $ file = sys_get_temp_dir ().'/cache-serializer.php ' ;
48+ @unlink ($ file );
49+
50+ $ warmer = new SerializerCacheWarmer ($ loaders , $ file );
51+ $ warmer ->warmUp (\dirname ($ file ), \dirname ($ file ));
52+
53+ $ this ->assertFileExists ($ file );
54+
55+ $ arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
56+
57+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
58+ }
59+
60+ #[IgnoreDeprecations]
61+ #[Group('legacy ' )]
62+ #[DataProvider('xmlLoaderProvider ' )]
63+ public function testXmlWarmUp (array $ loaders )
4464 {
4565 $ file = sys_get_temp_dir ().'/cache-serializer.php ' ;
4666 @unlink ($ file );
@@ -53,11 +73,31 @@ public function testWarmUp(array $loaders)
5373 $ arrayPool = $ this ->getArrayPool ($ file );
5474
5575 $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person ' )->isHit ());
76+ }
77+
78+ #[DataProvider('yamlLoaderProvider ' )]
79+ public function testYamlWarmUpAbsoluteFilePath (array $ loaders )
80+ {
81+ $ file = sys_get_temp_dir ().'/0/cache-serializer.php ' ;
82+ @unlink ($ file );
83+
84+ $ cacheDir = sys_get_temp_dir ().'/1 ' ;
85+
86+ $ warmer = new SerializerCacheWarmer ($ loaders , $ file );
87+ $ warmer ->warmUp ($ cacheDir , $ cacheDir );
88+
89+ $ this ->assertFileExists ($ file );
90+ $ this ->assertFileDoesNotExist ($ cacheDir .'/cache-serializer.php ' );
91+
92+ $ arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
93+
5694 $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
5795 }
5896
59- #[DataProvider('loaderProvider ' )]
60- public function testWarmUpAbsoluteFilePath (array $ loaders )
97+ #[IgnoreDeprecations]
98+ #[Group('legacy ' )]
99+ #[DataProvider('xmlLoaderProvider ' )]
100+ public function testXmlWarmUpAbsoluteFilePath (array $ loaders )
61101 {
62102 $ file = sys_get_temp_dir ().'/0/cache-serializer.php ' ;
63103 @unlink ($ file );
@@ -73,11 +113,10 @@ public function testWarmUpAbsoluteFilePath(array $loaders)
73113 $ arrayPool = $ this ->getArrayPool ($ file );
74114
75115 $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person ' )->isHit ());
76- $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
77116 }
78117
79- #[DataProvider('loaderProvider ' )]
80- public function testWarmUpWithoutBuildDir (array $ loaders )
118+ #[DataProvider('yamlLoaderProvider ' )]
119+ public function testYamlWarmUpWithoutBuildDir (array $ loaders )
81120 {
82121 $ file = sys_get_temp_dir ().'/cache-serializer.php ' ;
83122 @unlink ($ file );
@@ -89,30 +128,63 @@ public function testWarmUpWithoutBuildDir(array $loaders)
89128
90129 $ arrayPool = $ this ->getArrayPool ($ file );
91130
92- $ this ->assertFalse ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person ' )->isHit ());
93131 $ this ->assertFalse ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
94132 }
95133
96- public static function loaderProvider (): array
134+ #[IgnoreDeprecations]
135+ #[Group('legacy ' )]
136+ #[DataProvider('xmlLoaderProvider ' )]
137+ public function testXmlWarmUpWithoutBuildDir (array $ loaders )
138+ {
139+ $ file = sys_get_temp_dir ().'/cache-serializer.php ' ;
140+ @unlink ($ file );
141+
142+ $ warmer = new SerializerCacheWarmer ($ loaders , $ file );
143+ $ warmer ->warmUp (\dirname ($ file ));
144+
145+ $ this ->assertFileDoesNotExist ($ file );
146+
147+ $ arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
148+
149+ $ this ->assertFalse ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person ' )->isHit ());
150+ }
151+
152+ public static function yamlLoaderProvider (): array
97153 {
98154 return [
99155 [
100156 [
101157 new LoaderChain ([
102- new XmlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/person.xml ' ),
103158 new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/author.yml ' ),
104159 ]),
105160 ],
106161 ],
107162 [
108163 [
109- new XmlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/person.xml ' ),
110164 new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/author.yml ' ),
111165 ],
112166 ],
113167 ];
114168 }
115169
170+ public static function xmlLoaderProvider (): array
171+ {
172+ return [
173+ [
174+ [
175+ new LoaderChain ([
176+ new XmlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/person.xml ' ),
177+ ]),
178+ ],
179+ ],
180+ [
181+ [
182+ new XmlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/person.xml ' ),
183+ ],
184+ ],
185+ ];
186+ }
187+
116188 public function testWarmUpWithoutLoader ()
117189 {
118190 $ file = sys_get_temp_dir ().'/cache-serializer-without-loader.php ' ;
0 commit comments