@@ -30,9 +30,50 @@ public function testWarmUp(array $loaders)
30
30
@unlink ($ file );
31
31
32
32
$ warmer =new SerializerCacheWarmer ($ loaders ,$ file );
33
- $ warmer ->warmUp (\dirname ($ file ));
33
+ $ warmer ->warmUp (\dirname ($ file ),\dirname ($ file ));
34
+
35
+ $ this ->assertFileExists ($ file );
36
+
37
+ $ arrayPool =new PhpArrayAdapter ($ file ,new NullAdapter ());
38
+
39
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person ' )->isHit ());
40
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
41
+ }
42
+
43
+ /**
44
+ * @dataProvider loaderProvider
45
+ */
46
+ public function testWarmUpAbsoluteFilePath (array $ loaders )
47
+ {
48
+ $ file =sys_get_temp_dir ().'/0/cache-serializer.php ' ;
49
+ @unlink ($ file );
50
+
51
+ $ cacheDir =sys_get_temp_dir ().'/1 ' ;
52
+
53
+ $ warmer =new SerializerCacheWarmer ($ loaders ,$ file );
54
+ $ warmer ->warmUp ($ cacheDir ,$ cacheDir );
34
55
35
56
$ this ->assertFileExists ($ file );
57
+ $ this ->assertFileDoesNotExist ($ cacheDir .'/cache-serializer.php ' );
58
+
59
+ $ arrayPool =new PhpArrayAdapter ($ file ,new NullAdapter ());
60
+
61
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person ' )->isHit ());
62
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author ' )->isHit ());
63
+ }
64
+
65
+ /**
66
+ * @dataProvider loaderProvider
67
+ */
68
+ public function testWarmUpWithoutBuildDir (array $ loaders )
69
+ {
70
+ $ file =sys_get_temp_dir ().'/cache-serializer.php ' ;
71
+ @unlink ($ file );
72
+
73
+ $ warmer =new SerializerCacheWarmer ($ loaders ,$ file );
74
+ $ warmer ->warmUp (\dirname ($ file ));
75
+
76
+ $ this ->assertFileDoesNotExist ($ file );
36
77
37
78
$ arrayPool =new PhpArrayAdapter ($ file ,new NullAdapter ());
38
79
@@ -66,7 +107,7 @@ public function testWarmUpWithoutLoader()
66
107
@unlink ($ file );
67
108
68
109
$ warmer =new SerializerCacheWarmer ([],$ file );
69
- $ warmer ->warmUp (\dirname ($ file ));
110
+ $ warmer ->warmUp (\dirname ($ file ), \dirname ( $ file ) );
70
111
71
112
$ this ->assertFileExists ($ file );
72
113
}
@@ -79,15 +120,19 @@ public function testClassAutoloadException()
79
120
{
80
121
$ this ->assertFalse (class_exists ($ mappedClass ='AClassThatDoesNotExist_FWB_CacheWarmer_SerializerCacheWarmerTest ' ,false ));
81
122
82
- $ warmer =new SerializerCacheWarmer ([new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/does_not_exist.yaml ' )],tempnam (sys_get_temp_dir (),__FUNCTION__ ));
123
+ $ file =tempnam (sys_get_temp_dir (),__FUNCTION__ );
124
+ @unlink ($ file );
125
+
126
+ $ warmer =new SerializerCacheWarmer ([new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/does_not_exist.yaml ' )],$ file );
83
127
84
128
spl_autoload_register ($ classLoader =function ($ class )use ($ mappedClass ) {
85
129
if ($ class ===$ mappedClass ) {
86
130
throw new \DomainException ('This exception should be caught by the warmer. ' );
87
131
}
88
132
},true ,true );
89
133
90
- $ warmer ->warmUp ('foo ' );
134
+ $ warmer ->warmUp (\dirname ($ file ),\dirname ($ file ));
135
+ $ this ->assertFileExists ($ file );
91
136
92
137
spl_autoload_unregister ($ classLoader );
93
138
}
@@ -98,12 +143,12 @@ public function testClassAutoloadException()
98
143
*/
99
144
public function testClassAutoloadExceptionWithUnrelatedException ()
100
145
{
101
- $ this ->expectException (\DomainException::class);
102
- $ this ->expectExceptionMessage ('This exception should not be caught by the warmer. ' );
103
-
104
146
$ this ->assertFalse (class_exists ($ mappedClass ='AClassThatDoesNotExist_FWB_CacheWarmer_SerializerCacheWarmerTest ' ,false ));
105
147
106
- $ warmer =new SerializerCacheWarmer ([new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/does_not_exist.yaml ' )],tempnam (sys_get_temp_dir (),__FUNCTION__ ));
148
+ $ file =tempnam (sys_get_temp_dir (),__FUNCTION__ );
149
+ @unlink ($ file );
150
+
151
+ $ warmer =new SerializerCacheWarmer ([new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/does_not_exist.yaml ' )],basename ($ file ));
107
152
108
153
spl_autoload_register ($ classLoader =function ($ class )use ($ mappedClass ) {
109
154
if ($ class ===$ mappedClass ) {
@@ -112,8 +157,17 @@ public function testClassAutoloadExceptionWithUnrelatedException()
112
157
}
113
158
},true ,true );
114
159
115
- $ warmer ->warmUp ('foo ' );
160
+ $ this ->expectException (\DomainException::class);
161
+ $ this ->expectExceptionMessage ('This exception should not be caught by the warmer. ' );
162
+
163
+ try {
164
+ $ warmer ->warmUp (\dirname ($ file ),\dirname ($ file ));
165
+ }catch (\DomainException $ e ) {
166
+ $ this ->assertFileDoesNotExist ($ file );
116
167
117
- spl_autoload_unregister ($ classLoader );
168
+ throw $ e ;
169
+ }finally {
170
+ spl_autoload_unregister ($ classLoader );
171
+ }
118
172
}
119
173
}