public function testCacheIsFreshAfterCacheClearedWithWarmup() { $input = new ArrayInput(array('cache:clear')); $application = new Application($this->kernel); $application->setCatchExceptions(false); $application->doRun($input, new NullOutput()); // Ensure that all *.meta files are fresh $finder = new Finder(); $metaFiles = $finder->files()->in($this->kernel->getCacheDir())->name('*.php.meta'); // simply check that cache is warmed up $this->assertGreaterThanOrEqual(1, count($metaFiles)); $configCacheFactory = new ConfigCacheFactory(true); $that = $this; foreach ($metaFiles as $file) { $configCacheFactory->cache(substr($file, 0, -5), function () use($that, $file) { $that->fail(sprintf('Meta file "%s" is not fresh', (string) $file)); }); } // check that app kernel file present in meta file of container's cache $containerRef = new \ReflectionObject($this->kernel->getContainer()); $containerFile = $containerRef->getFileName(); $containerMetaFile = $containerFile . '.meta'; $kernelRef = new \ReflectionObject($this->kernel); $kernelFile = $kernelRef->getFileName(); /** @var ResourceInterface[] $meta */ $meta = unserialize(file_get_contents($containerMetaFile)); $found = false; foreach ($meta as $resource) { if ((string) $resource === $kernelFile) { $found = true; break; } } $this->assertTrue($found, 'Kernel file should present as resource'); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Invalid type for callback argument. Expected callable, but got "object". */ public function testCachWithInvalidCallback() { $cacheFactory = new ConfigCacheFactory(true); $cacheFactory->cache('file', new \stdClass()); }