Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FrameworkBundle] cache:clear command fills *.php.meta files with wro…
…ng data
- Loading branch information
Showing
4 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand\Fixture\TestAppKernel; | ||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; | ||
use Symfony\Component\Config\ConfigCache; | ||
use Symfony\Component\Config\Resource\ResourceInterface; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
class CacheClearCommandTest extends TestCase | ||
{ | ||
/** @var TestAppKernel */ | ||
private $kernel; | ||
/** @var Filesystem */ | ||
private $fs; | ||
private $rootDir; | ||
|
||
protected function setUp() | ||
{ | ||
$this->fs = new Filesystem(); | ||
$this->kernel = new TestAppKernel('test', true); | ||
$this->rootDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('sf2_cache_'); | ||
$this->kernel->setRootDir($this->rootDir); | ||
$this->fs->mkdir($this->rootDir); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->fs->remove($this->rootDir); | ||
} | ||
|
||
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)); | ||
foreach ($metaFiles as $file) { | ||
$configCache = new ConfigCache(substr($file, 0, -5), true); | ||
$this->assertTrue( | ||
$configCache->isFresh(), | ||
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'); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand\Fixture; | ||
|
||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class TestAppKernel extends Kernel | ||
{ | ||
public function registerBundles() | ||
{ | ||
return array( | ||
new FrameworkBundle(), | ||
); | ||
} | ||
|
||
public function setRootDir($rootDir) | ||
{ | ||
$this->rootDir = $rootDir; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
$loader->load(__DIR__.DIRECTORY_SEPARATOR.'config.yml'); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
framework: | ||
secret: test |