Skip to content

Commit cbd5ec7

Browse files
[HttkKernel] fix cleaning legacy containers
1 parent cd6690d commit cbd5ec7

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ protected function initializeContainer()
662662
$oldContainerDir = dirname($oldContainer->getFileName());
663663
foreach (glob(dirname($oldContainerDir).'/*.legacy') as $legacyContainer) {
664664
if ($oldContainerDir.'.legacy' !== $legacyContainer && @unlink($legacyContainer)) {
665-
(new Filesystem())->remove(substr($legacyContainer, 0, -16));
665+
(new Filesystem())->remove(substr($legacyContainer, 0, -7));
666666
}
667667
}
668668

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@ public function testClone()
6565
$this->assertNull($clone->getContainer());
6666
}
6767

68+
public function testInitializeContainerClearsOldContainers()
69+
{
70+
$fs = new Filesystem();
71+
$legacyContainerDir = __DIR__.'/Fixtures/cache/custom/ContainerA123456';
72+
$fs->mkdir($legacyContainerDir);
73+
touch($legacyContainerDir.'.legacy');
74+
75+
$kernel = new CustomProjectDirKernel();
76+
$kernel->boot();
77+
78+
$containerDir = __DIR__.'/Fixtures/cache/custom/'.substr(get_class($kernel->getContainer()), 0, 16);
79+
$this->assertTrue(unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'));
80+
$this->assertFileExists($containerDir);
81+
$this->assertFileNotExists($containerDir.'.legacy');
82+
83+
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
84+
$kernel->boot();
85+
86+
$this->assertFileExists($containerDir);
87+
$this->assertFileExists($containerDir.'.legacy');
88+
89+
$this->assertFileNotExists($legacyContainerDir);
90+
$this->assertFileNotExists($legacyContainerDir.'.legacy');
91+
}
92+
6893
public function testBootInitializesBundlesAndContainer()
6994
{
7095
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
@@ -1022,7 +1047,7 @@ protected function getHttpKernel()
10221047

10231048
class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
10241049
{
1025-
public function __construct(\Closure $buildContainer = null)
1050+
public function __construct()
10261051
{
10271052
parent::__construct();
10281053
Kernel::__construct('pass', true);

0 commit comments

Comments
 (0)