@@ -32,7 +32,7 @@ public function testWarmUp()
3232 @unlink ($ file );
3333
3434 $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
35- $ warmer ->warmUp (\dirname ($ file ));
35+ $ warmer ->warmUp (\dirname ($ file ), \dirname ( $ file ) );
3636
3737 $ this ->assertFileExists ($ file );
3838
@@ -42,6 +42,53 @@ public function testWarmUp()
4242 $ this ->assertTrue ($ arrayPool ->getItem ('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author ' )->isHit ());
4343 }
4444
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+
4592 public function testWarmUpWithAnnotations ()
4693 {
4794 $ validatorBuilder = new ValidatorBuilder ();
@@ -52,7 +99,7 @@ public function testWarmUpWithAnnotations()
5299 @unlink ($ file );
53100
54101 $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
55- $ warmer ->warmUp (\dirname ($ file ));
102+ $ warmer ->warmUp (\dirname ($ file ), \dirname ( $ file ) );
56103
57104 $ this ->assertFileExists ($ file );
58105
@@ -72,7 +119,7 @@ public function testWarmUpWithoutLoader()
72119 @unlink ($ file );
73120
74121 $ warmer = new ValidatorCacheWarmer ($ validatorBuilder , $ file );
75- $ warmer ->warmUp (\dirname ($ file ));
122+ $ warmer ->warmUp (\dirname ($ file ), \dirname ( $ file ) );
76123
77124 $ this ->assertFileExists ($ file );
78125 }
@@ -85,17 +132,22 @@ public function testClassAutoloadException()
85132 {
86133 $ this ->assertFalse (class_exists ($ mappedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_ValidatorCacheWarmerTest ' , false ));
87134
135+ $ file = tempnam (sys_get_temp_dir (), __FUNCTION__ );
136+ @unlink ($ file );
137+
88138 $ validatorBuilder = new ValidatorBuilder ();
89139 $ 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 );
91141
92142 spl_autoload_register ($ classloader = function ($ class ) use ($ mappedClass ) {
93143 if ($ class === $ mappedClass ) {
94144 throw new \DomainException ('This exception should be caught by the warmer. ' );
95145 }
96146 }, true , true );
97147
98- $ warmer ->warmUp ('foo ' );
148+ $ warmer ->warmUp (\dirname ($ file ), \dirname ($ file ));
149+
150+ $ this ->assertFileExists ($ file );
99151
100152 spl_autoload_unregister ($ classloader );
101153 }
@@ -106,14 +158,14 @@ public function testClassAutoloadException()
106158 */
107159 public function testClassAutoloadExceptionWithUnrelatedException ()
108160 {
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 );
111163
112164 $ this ->assertFalse (class_exists ($ mappedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_ValidatorCacheWarmerTest ' , false ));
113165
114166 $ validatorBuilder = new ValidatorBuilder ();
115167 $ 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 ));
117169
118170 spl_autoload_register ($ classLoader = function ($ class ) use ($ mappedClass ) {
119171 if ($ class === $ mappedClass ) {
@@ -122,8 +174,17 @@ public function testClassAutoloadExceptionWithUnrelatedException()
122174 }
123175 }, true , true );
124176
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 );
126184
127- spl_autoload_unregister ($ classLoader );
185+ throw $ e ;
186+ } finally {
187+ spl_autoload_unregister ($ classLoader );
188+ }
128189 }
129190}
0 commit comments