From 8cb28bf7517d1c2e27da4d3eeb557fbffedc1ec8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 5 Sep 2016 09:18:51 +0200 Subject: [PATCH] [DI] Add anti-regression test --- .../Tests/ContainerTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 013ee82316..e451806bb7 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -256,6 +256,18 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $this->assertNull($sc->get('inactive', ContainerInterface::NULL_ON_INVALID_REFERENCE)); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExcepionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service. + */ + public function testGetSyntheticServiceAlwaysThrows() + { + require_once __DIR__.'/Fixtures/php/services9.php'; + + $container = new \ProjectServiceContainer(); + $container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE); + } + public function testHas() { $sc = new ProjectServiceContainer(); @@ -287,14 +299,17 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $container->addScope(new Scope('foo')); $container->enterScope('foo'); + $container->set('foo', new \stdClass(), 'foo'); $scoped1 = $container->get('scoped'); $scopedFoo1 = $container->get('scoped_foo'); $container->enterScope('foo'); + $container->set('foo', new \stdClass(), 'foo'); $scoped2 = $container->get('scoped'); $scoped3 = $container->get('SCOPED'); $scopedFoo2 = $container->get('scoped_foo'); + $container->set('foo', null, 'foo'); $container->leaveScope('foo'); $scoped4 = $container->get('scoped'); $scopedFoo3 = $container->get('scoped_foo'); @@ -641,6 +656,12 @@ class ProjectServiceContainer extends Container return $this->services['scoped_bar'] = $this->scopedServices['foo']['scoped_bar'] = new \stdClass(); } + protected function synchronizeFooService() + { + // Typically get the service to pass it to a setter + $this->get('foo'); + } + protected function synchronizeScopedSynchronizedFooService() { $this->synchronized = true;