[HttpKernel] fix cleaning legacy containers
This commit is contained in:
parent
cd6690dacd
commit
324821d97c
@ -662,7 +662,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
|||||||
$oldContainerDir = dirname($oldContainer->getFileName());
|
$oldContainerDir = dirname($oldContainer->getFileName());
|
||||||
foreach (glob(dirname($oldContainerDir).'/*.legacy') as $legacyContainer) {
|
foreach (glob(dirname($oldContainerDir).'/*.legacy') as $legacyContainer) {
|
||||||
if ($oldContainerDir.'.legacy' !== $legacyContainer && @unlink($legacyContainer)) {
|
if ($oldContainerDir.'.legacy' !== $legacyContainer && @unlink($legacyContainer)) {
|
||||||
(new Filesystem())->remove(substr($legacyContainer, 0, -16));
|
(new Filesystem())->remove(substr($legacyContainer, 0, -7));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,31 @@ class KernelTest extends TestCase
|
|||||||
$this->assertNull($clone->getContainer());
|
$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()
|
public function testBootInitializesBundlesAndContainer()
|
||||||
{
|
{
|
||||||
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
|
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
|
||||||
@ -1022,7 +1047,7 @@ class CustomProjectDirKernel extends Kernel
|
|||||||
|
|
||||||
class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
|
class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
|
||||||
{
|
{
|
||||||
public function __construct(\Closure $buildContainer = null)
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
Kernel::__construct('pass', true);
|
Kernel::__construct('pass', true);
|
||||||
|
Reference in New Issue
Block a user