[HttpKernel] fix cleaning legacy containers

This commit is contained in:
Nicolas Grekas 2017-12-23 19:44:20 +01:00
parent cd6690dacd
commit 324821d97c
2 changed files with 27 additions and 2 deletions

View File

@ -662,7 +662,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$oldContainerDir = dirname($oldContainer->getFileName());
foreach (glob(dirname($oldContainerDir).'/*.legacy') as $legacyContainer) {
if ($oldContainerDir.'.legacy' !== $legacyContainer && @unlink($legacyContainer)) {
(new Filesystem())->remove(substr($legacyContainer, 0, -16));
(new Filesystem())->remove(substr($legacyContainer, 0, -7));
}
}

View File

@ -65,6 +65,31 @@ class KernelTest extends TestCase
$this->assertNull($clone->getContainer());
}
public function testInitializeContainerClearsOldContainers()
{
$fs = new Filesystem();
$legacyContainerDir = __DIR__.'/Fixtures/cache/custom/ContainerA123456';
$fs->mkdir($legacyContainerDir);
touch($legacyContainerDir.'.legacy');
$kernel = new CustomProjectDirKernel();
$kernel->boot();
$containerDir = __DIR__.'/Fixtures/cache/custom/'.substr(get_class($kernel->getContainer()), 0, 16);
$this->assertTrue(unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'));
$this->assertFileExists($containerDir);
$this->assertFileNotExists($containerDir.'.legacy');
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
$kernel->boot();
$this->assertFileExists($containerDir);
$this->assertFileExists($containerDir.'.legacy');
$this->assertFileNotExists($legacyContainerDir);
$this->assertFileNotExists($legacyContainerDir.'.legacy');
}
public function testBootInitializesBundlesAndContainer()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
@ -1022,7 +1047,7 @@ class CustomProjectDirKernel extends Kernel
class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
{
public function __construct(\Closure $buildContainer = null)
public function __construct()
{
parent::__construct();
Kernel::__construct('pass', true);