12
12
namespace Symfony \Bundle \FrameworkBundle \Tests \CacheWarmer ;
13
13
14
14
use PHPUnit \Framework \Attributes \DataProvider ;
15
+ use PHPUnit \Framework \Attributes \Group ;
16
+ use PHPUnit \Framework \Attributes \IgnoreDeprecations ;
15
17
use Symfony \Bundle \FrameworkBundle \CacheWarmer \SerializerCacheWarmer ;
16
18
use Symfony \Bundle \FrameworkBundle \Tests \TestCase ;
17
19
use Symfony \Component \Cache \Adapter \NullAdapter ;
@@ -39,8 +41,26 @@ private function getArrayPool(string $file): PhpArrayAdapter
39
41
return $ this ->arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
40
42
}
41
43
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 )
44
64
{
45
65
$ file = sys_get_temp_dir ().'/cache-serializer.php ' ;
46
66
@unlink ($ file );
@@ -53,11 +73,31 @@ public function testWarmUp(array $loaders)
53
73
$ arrayPool = $ this ->getArrayPool ($ file );
54
74
55
75
$ 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
+
56
94
$ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
57
95
}
58
96
59
- #[DataProvider('loaderProvider ' )]
60
- public function testWarmUpAbsoluteFilePath (array $ loaders )
97
+ #[IgnoreDeprecations]
98
+ #[Group('legacy ' )]
99
+ #[DataProvider('xmlLoaderProvider ' )]
100
+ public function testXmlWarmUpAbsoluteFilePath (array $ loaders )
61
101
{
62
102
$ file = sys_get_temp_dir ().'/0/cache-serializer.php ' ;
63
103
@unlink ($ file );
@@ -73,11 +113,10 @@ public function testWarmUpAbsoluteFilePath(array $loaders)
73
113
$ arrayPool = $ this ->getArrayPool ($ file );
74
114
75
115
$ 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 ());
77
116
}
78
117
79
- #[DataProvider('loaderProvider ' )]
80
- public function testWarmUpWithoutBuildDir (array $ loaders )
118
+ #[DataProvider('yamlLoaderProvider ' )]
119
+ public function testYamlWarmUpWithoutBuildDir (array $ loaders )
81
120
{
82
121
$ file = sys_get_temp_dir ().'/cache-serializer.php ' ;
83
122
@unlink ($ file );
@@ -89,30 +128,63 @@ public function testWarmUpWithoutBuildDir(array $loaders)
89
128
90
129
$ arrayPool = $ this ->getArrayPool ($ file );
91
130
92
- $ this ->assertFalse ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person ' )->isHit ());
93
131
$ this ->assertFalse ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
94
132
}
95
133
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
97
153
{
98
154
return [
99
155
[
100
156
[
101
157
new LoaderChain ([
102
- new XmlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/person.xml ' ),
103
158
new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/author.yml ' ),
104
159
]),
105
160
],
106
161
],
107
162
[
108
163
[
109
- new XmlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/person.xml ' ),
110
164
new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/author.yml ' ),
111
165
],
112
166
],
113
167
];
114
168
}
115
169
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
+
116
188
public function testWarmUpWithoutLoader ()
117
189
{
118
190
$ file = sys_get_temp_dir ().'/cache-serializer-without-loader.php ' ;
0 commit comments