2020use Symfony \Component \Console \Output \NullOutput ;
2121use Symfony \Component \Filesystem \Filesystem ;
2222use Symfony \Component \Finder \Finder ;
23+ use Symfony \Component \HttpKernel \KernelInterface ;
2324
2425class CacheClearCommandTest extends TestCase
2526{
@@ -40,17 +41,18 @@ protected function tearDown(): void
4041 $ this ->fs ->remove ($ this ->kernel ->getProjectDir ());
4142 }
4243
43- public function testCacheIsFreshAfterCacheClearedWithWarmup ()
44+ /** @dataProvider getKernel */
45+ public function testCacheIsFreshAfterCacheClearedWithWarmup (KernelInterface $ kernel )
4446 {
4547 $ input = new ArrayInput (['cache:clear ' ]);
46- $ application = new Application ($ this -> kernel );
48+ $ application = new Application ($ kernel );
4749 $ application ->setCatchExceptions (false );
4850
4951 $ application ->doRun ($ input , new NullOutput ());
5052
5153 // Ensure that all *.meta files are fresh
5254 $ finder = new Finder ();
53- $ metaFiles = $ finder ->files ()->in ($ this -> kernel ->getCacheDir ())->name ('*.php.meta ' );
55+ $ metaFiles = $ finder ->files ()->in ($ kernel ->getCacheDir ())->name ('*.php.meta ' );
5456 // check that cache is warmed up
5557 $ this ->assertNotEmpty ($ metaFiles );
5658 $ configCacheFactory = new ConfigCacheFactory (true );
@@ -62,11 +64,11 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
6264 }
6365
6466 // 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 ' );
6668 $ containerRef = new \ReflectionClass ($ containerClass );
6769 $ containerFile = \dirname ($ containerRef ->getFileName (), 2 ).'/ ' .$ containerClass .'.php ' ;
6870 $ containerMetaFile = $ containerFile .'.meta ' ;
69- $ kernelRef = new \ReflectionObject ($ this -> kernel );
71+ $ kernelRef = new \ReflectionObject ($ kernel );
7072 $ kernelFile = $ kernelRef ->getFileName ();
7173 /** @var ResourceInterface[] $meta */
7274 $ meta = unserialize (file_get_contents ($ containerMetaFile ));
@@ -83,4 +85,21 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
8385 $ containerFile = str_replace ('tes_ ' .\DIRECTORY_SEPARATOR , 'test ' .\DIRECTORY_SEPARATOR , $ containerRef ->getFileName ());
8486 $ this ->assertMatchesRegularExpression (sprintf ('/ \'kernel.container_class \'\s*=>\s* \'%s \'/ ' , $ containerClass ), file_get_contents ($ containerFile ), 'kernel.container_class is properly set on the dumped container ' );
8587 }
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+ }
86105}
0 commit comments