@@ -29,10 +29,51 @@ public function testWarmUp(array $loaders)
29
29
$ file = sys_get_temp_dir ().'/cache-serializer.php ' ;
30
30
@unlink ($ file );
31
31
32
+ $ warmer = new SerializerCacheWarmer ($ loaders , basename ($ 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
+
32
53
$ warmer = new SerializerCacheWarmer ($ loaders , $ file );
33
- $ warmer ->warmUp (\dirname ( $ 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 , basename ($ file ));
74
+ $ warmer ->warmUp (\dirname ($ file ));
75
+
76
+ $ this ->assertFileDoesNotExist ($ file );
36
77
37
78
$ arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
38
79
@@ -65,8 +106,8 @@ public function testWarmUpWithoutLoader()
65
106
$ file = sys_get_temp_dir ().'/cache-serializer-without-loader.php ' ;
66
107
@unlink ($ file );
67
108
68
- $ warmer = new SerializerCacheWarmer ([], $ file );
69
- $ warmer ->warmUp (\dirname ($ file ));
109
+ $ warmer = new SerializerCacheWarmer ([], basename ( $ 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 ' )], basename ($ 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
}
@@ -103,7 +148,10 @@ public function testClassAutoloadExceptionWithUnrelatedException()
103
148
104
149
$ this ->assertFalse (class_exists ($ mappedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_SerializerCacheWarmerTest ' , false ));
105
150
106
- $ warmer = new SerializerCacheWarmer ([new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/does_not_exist.yaml ' )], tempnam (sys_get_temp_dir (), __FUNCTION__ ));
151
+ $ file = tempnam (sys_get_temp_dir (), __FUNCTION__ );
152
+ @unlink ($ file );
153
+
154
+ $ warmer = new SerializerCacheWarmer ([new YamlFileLoader (__DIR__ .'/../Fixtures/Serialization/Resources/does_not_exist.yaml ' )], basename ($ file ));
107
155
108
156
spl_autoload_register ($ classLoader = function ($ class ) use ($ mappedClass ) {
109
157
if ($ class === $ mappedClass ) {
@@ -112,8 +160,12 @@ public function testClassAutoloadExceptionWithUnrelatedException()
112
160
}
113
161
}, true , true );
114
162
115
- $ warmer ->warmUp ('foo ' );
163
+ try {
164
+ $ warmer ->warmUp (\dirname ($ file ), \dirname ($ file ));
165
+ } finally {
166
+ $ this ->assertFileDoesNotExist ($ file );
116
167
117
- spl_autoload_unregister ($ classLoader );
168
+ spl_autoload_unregister ($ classLoader );
169
+ }
118
170
}
119
171
}
0 commit comments