diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php index b5eeb901342db..2cf3d4a18d1bb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php @@ -38,8 +38,7 @@ public function testEvaluateWithoutAvailableRequest() $loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader'); $engine = new PhpEngine(new TemplateNameParser(), $container, $loader, new GlobalVariables($container)); - $container->set('request_stack', null); - + $this->assertFalse($container->has('request_stack')); $globals = $engine->getGlobals(); $this->assertEmpty($globals['app']->getRequest()); } diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 43b210ea6811b..376c4b5aa5c2b 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -190,7 +190,13 @@ public function set($id, $service) @trigger_error(sprintf('Unsetting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); unset($this->privates[$id]); } else { - @trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. A new public service will be created instead.', $id), E_USER_DEPRECATED); + @trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); + } + } elseif (isset($this->methodMap[$id])) { + if (null === $service) { + @trigger_error(sprintf('Unsetting the "%s" pre-defined service is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); + } else { + @trigger_error(sprintf('Setting the "%s" pre-defined service is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); } } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 67d73f53a0689..647cdab8fbcb3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -163,6 +163,22 @@ public function testSetReplacesAlias() $this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias'); } + /** + * @group legacy + * @expectedDeprecation Unsetting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0. + */ + public function testSetWithNullResetPredefinedService() + { + $sc = new Container(); + $sc->set('foo', new \stdClass()); + $sc->set('foo', null); + $this->assertFalse($sc->has('foo'), '->set() with null service resets the service'); + + $sc = new ProjectServiceContainer(); + $sc->set('bar', null); + $this->assertTrue($sc->has('bar'), '->set() with null service resets the pre-defined service'); + } + public function testGet() { $sc = new ProjectServiceContainer(); @@ -172,9 +188,6 @@ public function testGet() $this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined'); $this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined'); - $sc->set('bar', $bar = new \stdClass()); - $this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()'); - try { $sc->get(''); $this->fail('->get() throws a \InvalidArgumentException exception if the service is empty'); @@ -337,7 +350,7 @@ public function testInitialized() $this->assertFalse($sc->initialized('bar'), '->initialized() returns false if a service is defined, but not currently loaded'); $this->assertFalse($sc->initialized('alias'), '->initialized() returns false if an aliased service is not initialized'); - $sc->set('bar', new \stdClass()); + $sc->get('bar'); $this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized'); } @@ -426,7 +439,7 @@ public function testUnsetInternalPrivateServiceIsDeprecated() /** * @group legacy - * @expectedDeprecation Setting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0. A new public service will be created instead. + * @expectedDeprecation Setting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0. */ public function testChangeInternalPrivateServiceIsDeprecated() { @@ -453,6 +466,19 @@ public function testRequestAnInternalSharedPrivateServiceIsDeprecated() $c = new ProjectServiceContainer(); $c->get('internal'); } + + /** + * @group legacy + * @expectedDeprecation Setting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0. + */ + public function testReplacingAPreDefinedServiceIsDeprecated() + { + $c = new ProjectServiceContainer(); + $c->set('bar', new \stdClass()); + $c->set('bar', $bar = new \stdClass()); + + $this->assertSame($bar, $c->get('bar'), '->set() replaces a pre-defined service'); + } } class ProjectServiceContainer extends Container @@ -490,7 +516,7 @@ protected function getInternalService() protected function getBarService() { - return $this->__bar; + return $this->services['bar'] = $this->__bar; } protected function getFooBarService() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index bb8dfbb68bd62..655dfc0cb7d37 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -241,13 +241,13 @@ public function provideInvalidFactories() public function testAliases() { $container = include self::$fixturesPath.'/containers/container9.php'; + $container->setParameter('foo_bar', 'foo_bar'); $container->compile(); $dumper = new PhpDumper($container); eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Aliases'))); $container = new \Symfony_DI_PhpDumper_Test_Aliases(); - $container->set('foo', $foo = new \stdClass()); - $this->assertSame($foo, $container->get('foo')); + $foo = $container->get('foo'); $this->assertSame($foo, $container->get('alias_for_foo')); $this->assertSame($foo, $container->get('alias_for_alias')); } @@ -264,6 +264,10 @@ public function testFrozenContainerWithoutAliases() $this->assertFalse($container->has('foo')); } + /** + * @group legacy + * @expectedDeprecation Setting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0. + */ public function testOverrideServiceWhenUsingADumpedContainer() { require_once self::$fixturesPath.'/php/services9.php'; @@ -276,6 +280,10 @@ public function testOverrideServiceWhenUsingADumpedContainer() $this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service'); } + /** + * @group legacy + * @expectedDeprecation Setting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0. + */ public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne() { require_once self::$fixturesPath.'/php/services9.php'; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 91e32b52fe815..6d1cc0cb3a9f2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -1,6 +1,7 @@
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: