@@ -32,7 +32,7 @@ public function testWarmUp()
32
32
@unlink ($ file );
33
33
34
34
$ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
35
- $ warmer ->warmUp (\dirname ($ file ));
35
+ $ warmer ->warmUp (\dirname ($ file ), \dirname ( $ file ) );
36
36
37
37
$ this ->assertFileExists ($ file );
38
38
@@ -42,6 +42,53 @@ public function testWarmUp()
42
42
$ this ->assertTrue ($ arrayPool ->getItem ('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author ' )->isHit ());
43
43
}
44
44
45
+ public function testWarmUpAbsoluteFilePath ()
46
+ {
47
+ $ validatorBuilder = new ValidatorBuilder ();
48
+ $ validatorBuilder ->addXmlMapping (__DIR__ .'/../Fixtures/Validation/Resources/person.xml ' );
49
+ $ validatorBuilder ->addYamlMapping (__DIR__ .'/../Fixtures/Validation/Resources/author.yml ' );
50
+ $ validatorBuilder ->addMethodMapping ('loadValidatorMetadata ' );
51
+ $ validatorBuilder ->enableAttributeMapping ();
52
+
53
+ $ file = sys_get_temp_dir ().'/0/cache-validator.php ' ;
54
+ @unlink ($ file );
55
+
56
+ $ cacheDir = sys_get_temp_dir ().'/1 ' ;
57
+
58
+ $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
59
+ $ warmer ->warmUp ($ cacheDir , $ cacheDir );
60
+
61
+ $ this ->assertFileExists ($ file );
62
+ $ this ->assertFileDoesNotExist ($ cacheDir .'/cache-validator.php ' );
63
+
64
+ $ arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
65
+
66
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person ' )->isHit ());
67
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author ' )->isHit ());
68
+ }
69
+
70
+ public function testWarmUpWithoutBuilDir ()
71
+ {
72
+ $ validatorBuilder = new ValidatorBuilder ();
73
+ $ validatorBuilder ->addXmlMapping (__DIR__ .'/../Fixtures/Validation/Resources/person.xml ' );
74
+ $ validatorBuilder ->addYamlMapping (__DIR__ .'/../Fixtures/Validation/Resources/author.yml ' );
75
+ $ validatorBuilder ->addMethodMapping ('loadValidatorMetadata ' );
76
+ $ validatorBuilder ->enableAttributeMapping ();
77
+
78
+ $ file = sys_get_temp_dir ().'/cache-validator.php ' ;
79
+ @unlink ($ file );
80
+
81
+ $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
82
+ $ warmer ->warmUp (\dirname ($ file ));
83
+
84
+ $ this ->assertFileDoesNotExist ($ file );
85
+
86
+ $ arrayPool = new PhpArrayAdapter ($ file , new NullAdapter ());
87
+
88
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person ' )->isHit ());
89
+ $ this ->assertTrue ($ arrayPool ->getItem ('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author ' )->isHit ());
90
+ }
91
+
45
92
public function testWarmUpWithAnnotations ()
46
93
{
47
94
$ validatorBuilder = new ValidatorBuilder ();
@@ -52,7 +99,7 @@ public function testWarmUpWithAnnotations()
52
99
@unlink ($ file );
53
100
54
101
$ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
55
- $ warmer ->warmUp (\dirname ($ file ));
102
+ $ warmer ->warmUp (\dirname ($ file ), \dirname ( $ file ) );
56
103
57
104
$ this ->assertFileExists ($ file );
58
105
@@ -72,7 +119,7 @@ public function testWarmUpWithoutLoader()
72
119
@unlink ($ file );
73
120
74
121
$ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
75
- $ warmer ->warmUp (\dirname ($ file ));
122
+ $ warmer ->warmUp (\dirname ($ file ), \dirname ( $ file ) );
76
123
77
124
$ this ->assertFileExists ($ file );
78
125
}
@@ -85,17 +132,22 @@ public function testClassAutoloadException()
85
132
{
86
133
$ this ->assertFalse (class_exists ($ mappedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_ValidatorCacheWarmerTest ' , false ));
87
134
135
+ $ file = tempnam (sys_get_temp_dir (), __FUNCTION__ );
136
+ @unlink ($ file );
137
+
88
138
$ validatorBuilder = new ValidatorBuilder ();
89
139
$ validatorBuilder ->addYamlMapping (__DIR__ .'/../Fixtures/Validation/Resources/does_not_exist.yaml ' );
90
- $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , tempnam ( sys_get_temp_dir (), __FUNCTION__ ) );
140
+ $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
91
141
92
142
spl_autoload_register ($ classloader = function ($ class ) use ($ mappedClass ) {
93
143
if ($ class === $ mappedClass ) {
94
144
throw new \DomainException ('This exception should be caught by the warmer. ' );
95
145
}
96
146
}, true , true );
97
147
98
- $ warmer ->warmUp ('foo ' );
148
+ $ warmer ->warmUp (\dirname ($ file ), \dirname ($ file ));
149
+
150
+ $ this ->assertFileExists ($ file );
99
151
100
152
spl_autoload_unregister ($ classloader );
101
153
}
@@ -106,14 +158,14 @@ public function testClassAutoloadException()
106
158
*/
107
159
public function testClassAutoloadExceptionWithUnrelatedException ()
108
160
{
109
- $ this -> expectException (\DomainException::class );
110
- $ this -> expectExceptionMessage ( ' This exception should not be caught by the warmer. ' );
161
+ $ file = tempnam ( sys_get_temp_dir (), __FUNCTION__ );
162
+ @ unlink ( $ file );
111
163
112
164
$ this ->assertFalse (class_exists ($ mappedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_ValidatorCacheWarmerTest ' , false ));
113
165
114
166
$ validatorBuilder = new ValidatorBuilder ();
115
167
$ validatorBuilder ->addYamlMapping (__DIR__ .'/../Fixtures/Validation/Resources/does_not_exist.yaml ' );
116
- $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , tempnam ( sys_get_temp_dir (), __FUNCTION__ ));
168
+ $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , basename ( $ file ));
117
169
118
170
spl_autoload_register ($ classLoader = function ($ class ) use ($ mappedClass ) {
119
171
if ($ class === $ mappedClass ) {
@@ -122,8 +174,17 @@ public function testClassAutoloadExceptionWithUnrelatedException()
122
174
}
123
175
}, true , true );
124
176
125
- $ warmer ->warmUp ('foo ' );
177
+ $ this ->expectException (\DomainException::class);
178
+ $ this ->expectExceptionMessage ('This exception should not be caught by the warmer. ' );
179
+
180
+ try {
181
+ $ warmer ->warmUp (\dirname ($ file ), \dirname ($ file ));
182
+ } catch (\DomainException $ e ) {
183
+ $ this ->assertFileDoesNotExist ($ file );
126
184
127
- spl_autoload_unregister ($ classLoader );
185
+ throw $ e ;
186
+ } finally {
187
+ spl_autoload_unregister ($ classLoader );
188
+ }
128
189
}
129
190
}