From 8bb4e4d332805a120eab58776ef5037a9ceb564e Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sun, 7 Jul 2013 14:58:42 +0200 Subject: [PATCH] [DI] Fixed bug requesting non existing service from dumped frozen container --- .../DependencyInjection/Dumper/PhpDumper.php | 6 +++++- .../Tests/Dumper/PhpDumperTest.php | 12 ++++++++++++ .../Tests/Fixtures/php/services10.php | 2 ++ .../Tests/Fixtures/php/services11.php | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 0c622747cc..cd8366ec74 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -849,7 +849,11 @@ EOF; private function addAliases() { if (!$aliases = $this->container->getAliases()) { - return ''; + if ($this->container->isFrozen()) { + return "\n \$this->aliases = array();\n"; + } else { + return ''; + } } $code = " \$this->aliases = array(\n"; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 0ea42d473b..1979d102d4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -134,6 +134,18 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase $this->assertSame($foo, $container->get('alias_for_alias')); } + public function testFrozenContainerWithoutAliases() + { + $container = new ContainerBuilder(); + $container->compile(); + + $dumper = new PhpDumper($container); + eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Frozen_No_Aliases'))); + + $container = new \Symfony_DI_PhpDumper_Test_Frozen_No_Aliases(); + $this->assertFalse($container->has('foo')); + } + public function testOverrideServiceWhenUsingADumpedContainer() { require_once self::$fixturesPath.'/php/services9.php'; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index 15c16709d3..8796df8ae5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -36,6 +36,8 @@ class ProjectServiceContainer extends Container $this->methodMap = array( 'test' => 'getTestService', ); + + $this->aliases = array(); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php index 89856038b2..e6aa3410a2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php @@ -34,6 +34,8 @@ class ProjectServiceContainer extends Container $this->methodMap = array( 'foo' => 'getFooService', ); + + $this->aliases = array(); } /**