20
20
use Symfony \Component \Console \Output \NullOutput ;
21
21
use Symfony \Component \Filesystem \Filesystem ;
22
22
use Symfony \Component \Finder \Finder ;
23
+ use Symfony \Component \HttpKernel \KernelInterface ;
23
24
24
25
class CacheClearCommandTest extends TestCase
25
26
{
@@ -40,17 +41,18 @@ protected function tearDown(): void
40
41
$ this ->fs ->remove ($ this ->kernel ->getProjectDir ());
41
42
}
42
43
43
- public function testCacheIsFreshAfterCacheClearedWithWarmup ()
44
+ /** @dataProvider getKernel */
45
+ public function testCacheIsFreshAfterCacheClearedWithWarmup (KernelInterface $ kernel )
44
46
{
45
47
$ input = new ArrayInput (['cache:clear ' ]);
46
- $ application = new Application ($ this -> kernel );
48
+ $ application = new Application ($ kernel );
47
49
$ application ->setCatchExceptions (false );
48
50
49
51
$ application ->doRun ($ input , new NullOutput ());
50
52
51
53
// Ensure that all *.meta files are fresh
52
54
$ finder = new Finder ();
53
- $ metaFiles = $ finder ->files ()->in ($ this -> kernel ->getCacheDir ())->name ('*.php.meta ' );
55
+ $ metaFiles = $ finder ->files ()->in ($ kernel ->getCacheDir ())->name ('*.php.meta ' );
54
56
// check that cache is warmed up
55
57
$ this ->assertNotEmpty ($ metaFiles );
56
58
$ configCacheFactory = new ConfigCacheFactory (true );
@@ -62,11 +64,11 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
62
64
}
63
65
64
66
// check that app kernel file present in meta file of container's cache
65
- $ containerClass = $ this -> kernel ->getContainer ()->getParameter ('kernel.container_class ' );
67
+ $ containerClass = $ kernel ->getContainer ()->getParameter ('kernel.container_class ' );
66
68
$ containerRef = new \ReflectionClass ($ containerClass );
67
69
$ containerFile = \dirname ($ containerRef ->getFileName (), 2 ).'/ ' .$ containerClass .'.php ' ;
68
70
$ containerMetaFile = $ containerFile .'.meta ' ;
69
- $ kernelRef = new \ReflectionObject ($ this -> kernel );
71
+ $ kernelRef = new \ReflectionObject ($ kernel );
70
72
$ kernelFile = $ kernelRef ->getFileName ();
71
73
/** @var ResourceInterface[] $meta */
72
74
$ meta = unserialize (file_get_contents ($ containerMetaFile ));
@@ -83,4 +85,21 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
83
85
$ containerFile = str_replace ('tes_ ' .\DIRECTORY_SEPARATOR , 'test ' .\DIRECTORY_SEPARATOR , $ containerRef ->getFileName ());
84
86
$ this ->assertMatchesRegularExpression (sprintf ('/ \'kernel.container_class \'\s*=>\s* \'%s \'/ ' , $ containerClass ), file_get_contents ($ containerFile ), 'kernel.container_class is properly set on the dumped container ' );
85
87
}
88
+
89
+ public function getKernel ()
90
+ {
91
+ yield [new TestAppKernel ('test ' , true )];
92
+ yield [new NoBuildDirKernel ('test ' , true )];
93
+ }
94
+ }
95
+
96
+ class NoBuildDirKernel extends TestAppKernel
97
+ {
98
+ protected function getKernelParameters ()
99
+ {
100
+ $ parameters = parent ::getKernelParameters ();
101
+ unset($ parameters ['kernel.build_dir ' ]);
102
+
103
+ return $ parameters ;
104
+ }
86
105
}
0 commit comments