Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / dependency-injection / Tests / ContainerTest.php
index 834fef32b19cb7f0367d60a402cd6cd14d5f57e4..a57f787972f22cacbd4924d274dc28d94a57ac85 100644 (file)
 namespace Symfony\Component\DependencyInjection\Tests;
 
 use PHPUnit\Framework\TestCase;
-use Symfony\Component\DependencyInjection\Scope;
+use Symfony\Component\DependencyInjection\Alias;
 use Symfony\Component\DependencyInjection\Container;
 use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
-use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
 
 class ContainerTest extends TestCase
 {
@@ -83,6 +83,11 @@ class ContainerTest extends TestCase
         $this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '->compile() copies the current parameters to the new parameter bag');
     }
 
+    /**
+     * @group legacy
+     * @expectedDeprecation The Symfony\Component\DependencyInjection\Container::isFrozen() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.
+     * @expectedDeprecation The Symfony\Component\DependencyInjection\Container::isFrozen() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.
+     */
     public function testIsFrozen()
     {
         $sc = new Container(new ParameterBag(array('foo' => 'bar')));
@@ -91,6 +96,20 @@ class ContainerTest extends TestCase
         $this->assertTrue($sc->isFrozen(), '->isFrozen() returns true if the parameters are frozen');
     }
 
+    public function testIsCompiled()
+    {
+        $sc = new Container(new ParameterBag(array('foo' => 'bar')));
+        $this->assertFalse($sc->isCompiled(), '->isCompiled() returns false if the container is not compiled');
+        $sc->compile();
+        $this->assertTrue($sc->isCompiled(), '->isCompiled() returns true if the container is compiled');
+    }
+
+    public function testIsCompiledWithFrozenParameters()
+    {
+        $sc = new Container(new FrozenParameterBag(array('foo' => 'bar')));
+        $this->assertFalse($sc->isCompiled(), '->isCompiled() returns false if the container is not compiled but the parameter bag is already frozen');
+    }
+
     public function testGetParameterBag()
     {
         $sc = new Container();
@@ -106,10 +125,6 @@ class ContainerTest extends TestCase
         $sc->setParameter('foo', 'baz');
         $this->assertEquals('baz', $sc->getParameter('foo'), '->setParameter() overrides previously set parameter');
 
-        $sc->setParameter('Foo', 'baz1');
-        $this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
-        $this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
-
         try {
             $sc->getParameter('baba');
             $this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist');
@@ -119,6 +134,20 @@ class ContainerTest extends TestCase
         }
     }
 
+    /**
+     * @group legacy
+     * @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.4.
+     * @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "foo" is deprecated since Symfony 3.4.
+     */
+    public function testGetSetParameterWithMixedCase()
+    {
+        $sc = new Container(new ParameterBag(array('foo' => 'bar')));
+
+        $sc->setParameter('Foo', 'baz1');
+        $this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
+        $this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
+    }
+
     public function testGetServiceIds()
     {
         $sc = new Container();
@@ -128,14 +157,26 @@ class ContainerTest extends TestCase
 
         $sc = new ProjectServiceContainer();
         $sc->set('foo', $obj = new \stdClass());
-        $this->assertEquals(array('scoped', 'scoped_foo', 'scoped_synchronized_foo', 'inactive', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
+        $this->assertEquals(array('service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
+    }
+
+    /**
+     * @group legacy
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     */
+    public function testGetLegacyServiceIds()
+    {
+        $sc = new LegacyProjectServiceContainer();
+        $sc->set('foo', $obj = new \stdClass());
+
+        $this->assertEquals(array('internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
     }
 
     public function testSet()
     {
         $sc = new Container();
-        $sc->set('foo', $foo = new \stdClass());
-        $this->assertSame($foo, $sc->get('foo'), '->set() sets a service');
+        $sc->set('._. \\o/', $foo = new \stdClass());
+        $this->assertSame($foo, $sc->get('._. \\o/'), '->set() sets a service');
     }
 
     public function testSetWithNullResetTheService()
@@ -145,66 +186,97 @@ class ContainerTest extends TestCase
         $this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
     }
 
-    /**
-     * @expectedException \InvalidArgumentException
-     * @group legacy
-     */
-    public function testSetDoesNotAllowPrototypeScope()
+    public function testSetReplacesAlias()
     {
-        $c = new Container();
-        $c->set('foo', new \stdClass(), Container::SCOPE_PROTOTYPE);
+        $c = new ProjectServiceContainer();
+
+        $c->set('alias', $foo = new \stdClass());
+        $this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
     }
 
     /**
-     * @expectedException \RuntimeException
      * @group legacy
+     * @expectedDeprecation The "bar" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.
      */
-    public function testSetDoesNotAllowInactiveScope()
+    public function testSetWithNullOnInitializedPredefinedService()
     {
-        $c = new Container();
-        $c->addScope(new Scope('foo'));
-        $c->set('foo', new \stdClass(), 'foo');
+        $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->get('bar');
+        $sc->set('bar', null);
+        $this->assertTrue($sc->has('bar'), '->set() with null service resets the pre-defined service');
     }
 
-    /**
-     * @group legacy
-     */
-    public function testSetAlsoSetsScopedService()
+    public function testSetWithNullOnUninitializedPredefinedService()
     {
-        $c = new Container();
-        $c->addScope(new Scope('foo'));
-        $c->enterScope('foo');
-        $c->set('foo', $foo = new \stdClass(), 'foo');
+        $sc = new Container();
+        $sc->set('foo', new \stdClass());
+        $sc->get('foo', null);
+        $sc->set('foo', null);
+        $this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
 
-        $scoped = $this->getField($c, 'scopedServices');
-        $this->assertTrue(isset($scoped['foo']['foo']), '->set() sets a scoped service');
-        $this->assertSame($foo, $scoped['foo']['foo'], '->set() sets a scoped 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();
+        $sc->set('foo', $foo = new \stdClass());
+        $this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
+        $this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
+        $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');
+
+        try {
+            $sc->get('');
+            $this->fail('->get() throws a \InvalidArgumentException exception if the service is empty');
+        } catch (\Exception $e) {
+            $this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws a ServiceNotFoundException exception if the service is empty');
+        }
+        $this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty');
     }
 
     /**
      * @group legacy
+     * @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.3.
      */
-    public function testSetAlsoCallsSynchronizeService()
+    public function testGetInsensitivity()
     {
-        $c = new ProjectServiceContainer();
-        $c->addScope(new Scope('foo'));
-        $c->enterScope('foo');
-        $c->set('scoped_synchronized_foo', $bar = new \stdClass(), 'foo');
-        $this->assertTrue($c->synchronized, '->set() calls synchronize*Service() if it is defined for the service');
+        $sc = new ProjectServiceContainer();
+        $sc->set('foo', $foo = new \stdClass());
+        $this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
     }
 
-    public function testSetReplacesAlias()
+    /**
+     * @group legacy
+     * @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "foo" instead of "Foo" is deprecated since Symfony 3.3.
+     */
+    public function testNormalizeIdKeepsCase()
     {
-        $c = new ProjectServiceContainer();
-
-        $c->set('alias', $foo = new \stdClass());
-        $this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
+        $sc = new ProjectServiceContainer();
+        $sc->normalizeId('Foo', true);
+        $this->assertSame('Foo', $sc->normalizeId('foo'));
     }
 
-    public function testGet()
+    /**
+     * @group legacy
+     * @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.3.
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     */
+    public function testLegacyGet()
     {
-        $sc = new ProjectServiceContainer();
+        $sc = new LegacyProjectServiceContainer();
         $sc->set('foo', $foo = new \stdClass());
+
         $this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
         $this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
         $this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
@@ -260,24 +332,27 @@ class ContainerTest extends TestCase
     }
 
     /**
-     * @group legacy
+     * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
+     * @expectedExceptionMessage The "request" service is synthetic, it needs to be set at boot time before it can be used.
      */
-    public function testGetReturnsNullOnInactiveScope()
+    public function testGetSyntheticServiceThrows()
     {
-        $sc = new ProjectServiceContainer();
-        $this->assertNull($sc->get('inactive', ContainerInterface::NULL_ON_INVALID_REFERENCE));
+        require_once __DIR__.'/Fixtures/php/services9_compiled.php';
+
+        $container = new \ProjectServiceContainer();
+        $container->get('request');
     }
 
     /**
-     * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
-     * @expectedExceptionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
+     * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
+     * @expectedExceptionMessage The "inlined" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
      */
-    public function testGetSyntheticServiceAlwaysThrows()
+    public function testGetRemovedServiceThrows()
     {
-        require_once __DIR__.'/Fixtures/php/services9.php';
+        require_once __DIR__.'/Fixtures/php/services9_compiled.php';
 
         $container = new \ProjectServiceContainer();
-        $container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE);
+        $container->get('inlined');
     }
 
     public function testHas()
@@ -289,6 +364,25 @@ class ContainerTest extends TestCase
         $this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
         $this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
         $this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
+    }
+
+    /**
+     * @group legacy
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     * @expectedDeprecation Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
+     */
+    public function testLegacyHas()
+    {
+        $sc = new LegacyProjectServiceContainer();
+        $sc->set('foo', new \stdClass());
+
+        $this->assertFalse($sc->has('foo1'), '->has() returns false if the service does not exist');
+        $this->assertTrue($sc->has('foo'), '->has() returns true if the service exists');
+        $this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
+        $this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
+        $this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
         $this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
     }
 
@@ -301,416 +395,248 @@ class ContainerTest extends TestCase
         $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');
     }
 
-    public function testReset()
-    {
-        $c = new Container();
-        $c->set('bar', new \stdClass());
-
-        $c->reset();
-
-        $this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
-    }
-
     /**
-     * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
-     * @expectedExceptionMessage Resetting the container is not allowed when a scope is active.
      * @group legacy
+     * @expectedDeprecation Checking for the initialization of the "internal" private service is deprecated since Symfony 3.4 and won't be supported anymore in Symfony 4.0.
      */
-    public function testCannotResetInActiveScope()
+    public function testInitializedWithPrivateService()
     {
-        $c = new Container();
-        $c->addScope(new Scope('foo'));
-        $c->set('bar', new \stdClass());
-
-        $c->enterScope('foo');
-
-        $c->reset();
+        $sc = new ProjectServiceContainer();
+        $sc->get('internal_dependency');
+        $this->assertTrue($sc->initialized('internal'));
     }
 
-    /**
-     * @group legacy
-     */
-    public function testResetAfterLeavingScope()
+    public function testReset()
     {
         $c = new Container();
-        $c->addScope(new Scope('foo'));
         $c->set('bar', new \stdClass());
 
-        $c->enterScope('foo');
-        $c->leaveScope('foo');
-
         $c->reset();
 
         $this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
     }
 
     /**
-     * @group legacy
+     * @expectedException \Exception
+     * @expectedExceptionMessage Something went terribly wrong!
      */
-    public function testEnterLeaveCurrentScope()
+    public function testGetThrowsException()
     {
-        $container = new ProjectServiceContainer();
-        $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');
+        $c = new ProjectServiceContainer();
 
-        $container->set('foo', null, 'foo');
-        $container->leaveScope('foo');
-        $scoped4 = $container->get('scoped');
-        $scopedFoo3 = $container->get('scoped_foo');
+        try {
+            $c->get('throw_exception');
+        } catch (\Exception $e) {
+            // Do nothing.
+        }
 
-        $this->assertNotSame($scoped1, $scoped2);
-        $this->assertSame($scoped2, $scoped3);
-        $this->assertSame($scoped1, $scoped4);
-        $this->assertNotSame($scopedFoo1, $scopedFoo2);
-        $this->assertSame($scopedFoo1, $scopedFoo3);
+        // Retry, to make sure that get*Service() will be called.
+        $c->get('throw_exception');
     }
 
-    /**
-     * @group legacy
-     */
-    public function testEnterLeaveScopeWithChildScopes()
+    public function testGetThrowsExceptionOnServiceConfiguration()
     {
-        $container = new Container();
-        $container->addScope(new Scope('foo'));
-        $container->addScope(new Scope('bar', 'foo'));
-
-        $this->assertFalse($container->isScopeActive('foo'));
-
-        $container->enterScope('foo');
-        $container->enterScope('bar');
-
-        $this->assertTrue($container->isScopeActive('foo'));
-        $this->assertFalse($container->has('a'));
-
-        $a = new \stdClass();
-        $container->set('a', $a, 'bar');
+        $c = new ProjectServiceContainer();
 
-        $scoped = $this->getField($container, 'scopedServices');
-        $this->assertTrue(isset($scoped['bar']['a']));
-        $this->assertSame($a, $scoped['bar']['a']);
-        $this->assertTrue($container->has('a'));
+        try {
+            $c->get('throws_exception_on_service_configuration');
+        } catch (\Exception $e) {
+            // Do nothing.
+        }
 
-        $container->leaveScope('foo');
+        $this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
 
-        $scoped = $this->getField($container, 'scopedServices');
-        $this->assertFalse(isset($scoped['bar']));
-        $this->assertFalse($container->isScopeActive('foo'));
-        $this->assertFalse($container->has('a'));
+        // Retry, to make sure that get*Service() will be called.
+        try {
+            $c->get('throws_exception_on_service_configuration');
+        } catch (\Exception $e) {
+            // Do nothing.
+        }
+        $this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
     }
 
-    /**
-     * @group legacy
-     */
-    public function testEnterScopeRecursivelyWithInactiveChildScopes()
+    protected function getField($obj, $field)
     {
-        $container = new Container();
-        $container->addScope(new Scope('foo'));
-        $container->addScope(new Scope('bar', 'foo'));
-
-        $this->assertFalse($container->isScopeActive('foo'));
-
-        $container->enterScope('foo');
-
-        $this->assertTrue($container->isScopeActive('foo'));
-        $this->assertFalse($container->isScopeActive('bar'));
-        $this->assertFalse($container->has('a'));
-
-        $a = new \stdClass();
-        $container->set('a', $a, 'foo');
-
-        $scoped = $this->getField($container, 'scopedServices');
-        $this->assertTrue(isset($scoped['foo']['a']));
-        $this->assertSame($a, $scoped['foo']['a']);
-        $this->assertTrue($container->has('a'));
-
-        $container->enterScope('foo');
-
-        $scoped = $this->getField($container, 'scopedServices');
-        $this->assertFalse(isset($scoped['a']));
-        $this->assertTrue($container->isScopeActive('foo'));
-        $this->assertFalse($container->isScopeActive('bar'));
-        $this->assertFalse($container->has('a'));
-
-        $container->enterScope('bar');
-
-        $this->assertTrue($container->isScopeActive('bar'));
-
-        $container->leaveScope('foo');
+        $reflection = new \ReflectionProperty($obj, $field);
+        $reflection->setAccessible(true);
 
-        $this->assertTrue($container->isScopeActive('foo'));
-        $this->assertFalse($container->isScopeActive('bar'));
-        $this->assertTrue($container->has('a'));
+        return $reflection->getValue($obj);
     }
 
-    /**
-     * @group legacy
-     */
-    public function testEnterChildScopeRecursively()
+    public function testAlias()
     {
-        $container = new Container();
-        $container->addScope(new Scope('foo'));
-        $container->addScope(new Scope('bar', 'foo'));
-
-        $container->enterScope('foo');
-        $container->enterScope('bar');
-
-        $this->assertTrue($container->isScopeActive('bar'));
-        $this->assertFalse($container->has('a'));
-
-        $a = new \stdClass();
-        $container->set('a', $a, 'bar');
-
-        $scoped = $this->getField($container, 'scopedServices');
-        $this->assertTrue(isset($scoped['bar']['a']));
-        $this->assertSame($a, $scoped['bar']['a']);
-        $this->assertTrue($container->has('a'));
-
-        $container->enterScope('bar');
-
-        $scoped = $this->getField($container, 'scopedServices');
-        $this->assertFalse(isset($scoped['a']));
-        $this->assertTrue($container->isScopeActive('foo'));
-        $this->assertTrue($container->isScopeActive('bar'));
-        $this->assertFalse($container->has('a'));
-
-        $container->leaveScope('bar');
+        $c = new ProjectServiceContainer();
 
-        $this->assertTrue($container->isScopeActive('foo'));
-        $this->assertTrue($container->isScopeActive('bar'));
-        $this->assertTrue($container->has('a'));
+        $this->assertTrue($c->has('alias'));
+        $this->assertSame($c->get('alias'), $c->get('bar'));
     }
 
-    /**
-     * @expectedException \InvalidArgumentException
-     * @group legacy
-     */
-    public function testEnterScopeNotAdded()
+    public function testThatCloningIsNotSupported()
     {
-        $container = new Container();
-        $container->enterScope('foo');
+        $class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container');
+        $clone = $class->getMethod('__clone');
+        $this->assertFalse($class->isCloneable());
+        $this->assertTrue($clone->isPrivate());
     }
 
     /**
-     * @expectedException \RuntimeException
      * @group legacy
+     * @expectedDeprecation The "internal" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.
      */
-    public function testEnterScopeDoesNotAllowInactiveParentScope()
+    public function testUnsetInternalPrivateServiceIsDeprecated()
     {
-        $container = new Container();
-        $container->addScope(new Scope('foo'));
-        $container->addScope(new Scope('bar', 'foo'));
-        $container->enterScope('bar');
+        $c = new ProjectServiceContainer();
+        $c->set('internal', null);
     }
 
     /**
      * @group legacy
+     * @expectedDeprecation The "internal" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.
      */
-    public function testLeaveScopeNotActive()
+    public function testChangeInternalPrivateServiceIsDeprecated()
     {
-        $container = new Container();
-        $container->addScope(new Scope('foo'));
-
-        try {
-            $container->leaveScope('foo');
-            $this->fail('->leaveScope() throws a \LogicException if the scope is not active yet');
-        } catch (\Exception $e) {
-            $this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope is not active yet');
-            $this->assertEquals('The scope "foo" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope is not active yet');
-        }
-
-        try {
-            $container->leaveScope('bar');
-            $this->fail('->leaveScope() throws a \LogicException if the scope does not exist');
-        } catch (\Exception $e) {
-            $this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope does not exist');
-            $this->assertEquals('The scope "bar" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope does not exist');
-        }
+        $c = new ProjectServiceContainer();
+        $c->set('internal', $internal = new \stdClass());
+        $this->assertSame($c->get('internal'), $internal);
     }
 
     /**
-     * @expectedException \InvalidArgumentException
-     * @dataProvider getLegacyBuiltInScopes
      * @group legacy
+     * @expectedDeprecation The "internal" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.
      */
-    public function testAddScopeDoesNotAllowBuiltInScopes($scope)
+    public function testCheckExistenceOfAnInternalPrivateServiceIsDeprecated()
     {
-        $container = new Container();
-        $container->addScope(new Scope($scope));
+        $c = new ProjectServiceContainer();
+        $c->get('internal_dependency');
+        $this->assertTrue($c->has('internal'));
     }
 
     /**
-     * @expectedException \InvalidArgumentException
      * @group legacy
+     * @expectedDeprecation The "internal" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
      */
-    public function testAddScopeDoesNotAllowExistingScope()
+    public function testRequestAnInternalSharedPrivateServiceIsDeprecated()
     {
-        $container = new Container();
-        $container->addScope(new Scope('foo'));
-        $container->addScope(new Scope('foo'));
+        $c = new ProjectServiceContainer();
+        $c->get('internal_dependency');
+        $c->get('internal');
     }
 
     /**
-     * @expectedException \InvalidArgumentException
-     * @dataProvider getLegacyInvalidParentScopes
      * @group legacy
+     * @expectedDeprecation The "bar" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
      */
-    public function testAddScopeDoesNotAllowInvalidParentScope($scope)
+    public function testReplacingAPreDefinedServiceIsDeprecated()
     {
-        $c = new Container();
-        $c->addScope(new Scope('foo', $scope));
+        $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');
     }
 
     /**
      * @group legacy
+     * @expectedDeprecation The "synthetic" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.
      */
-    public function testAddScope()
+    public function testSetWithPrivateSyntheticServiceThrowsDeprecation()
     {
-        $c = new Container();
-        $c->addScope(new Scope('foo'));
-        $c->addScope(new Scope('bar', 'foo'));
+        $c = new ProjectServiceContainer();
+        $c->set('synthetic', new \stdClass());
+    }
+}
 
-        $this->assertSame(array('foo' => 'container', 'bar' => 'foo'), $this->getField($c, 'scopes'));
-        $this->assertSame(array('foo' => array('bar'), 'bar' => array()), $this->getField($c, 'scopeChildren'));
+class ProjectServiceContainer extends Container
+{
+    public $__bar;
+    public $__foo_bar;
+    public $__foo_baz;
+    public $__internal;
+    protected $privates;
+    protected $methodMap = array(
+        'internal' => 'getInternalService',
+        'bar' => 'getBarService',
+        'foo_bar' => 'getFooBarService',
+        'foo.baz' => 'getFoo_BazService',
+        'circular' => 'getCircularService',
+        'throw_exception' => 'getThrowExceptionService',
+        'throws_exception_on_service_configuration' => 'getThrowsExceptionOnServiceConfigurationService',
+        'internal_dependency' => 'getInternalDependencyService',
+    );
 
-        $c->addScope(new Scope('baz', 'bar'));
+    public function __construct()
+    {
+        parent::__construct();
 
-        $this->assertSame(array('foo' => 'container', 'bar' => 'foo', 'baz' => 'bar'), $this->getField($c, 'scopes'));
-        $this->assertSame(array('foo' => array('bar', 'baz'), 'bar' => array('baz'), 'baz' => array()), $this->getField($c, 'scopeChildren'));
+        $this->__bar = new \stdClass();
+        $this->__foo_bar = new \stdClass();
+        $this->__foo_baz = new \stdClass();
+        $this->__internal = new \stdClass();
+        $this->privates = array(
+            'internal' => true,
+            'synthetic' => true,
+        );
+        $this->aliases = array('alias' => 'bar');
+        $this->syntheticIds['synthetic'] = true;
     }
 
-    /**
-     * @group legacy
-     */
-    public function testHasScope()
+    protected function getInternalService()
     {
-        $c = new Container();
-
-        $this->assertFalse($c->hasScope('foo'));
-        $c->addScope(new Scope('foo'));
-        $this->assertTrue($c->hasScope('foo'));
+        return $this->services['internal'] = $this->__internal;
     }
 
-    /**
-     * @expectedException \Exception
-     * @expectedExceptionMessage Something went terribly wrong!
-     */
-    public function testGetThrowsException()
+    protected function getBarService()
     {
-        $c = new ProjectServiceContainer();
-
-        try {
-            $c->get('throw_exception');
-        } catch (\Exception $e) {
-            // Do nothing.
-        }
-
-        // Retry, to make sure that get*Service() will be called.
-        $c->get('throw_exception');
+        return $this->services['bar'] = $this->__bar;
     }
 
-    public function testGetThrowsExceptionOnServiceConfiguration()
+    protected function getFooBarService()
     {
-        $c = new ProjectServiceContainer();
-
-        try {
-            $c->get('throws_exception_on_service_configuration');
-        } catch (\Exception $e) {
-            // Do nothing.
-        }
-
-        $this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
-
-        // Retry, to make sure that get*Service() will be called.
-        try {
-            $c->get('throws_exception_on_service_configuration');
-        } catch (\Exception $e) {
-            // Do nothing.
-        }
-        $this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
+        return $this->__foo_bar;
     }
 
-    /**
-     * @group legacy
-     */
-    public function testIsScopeActive()
+    protected function getFoo_BazService()
     {
-        $c = new Container();
-
-        $this->assertFalse($c->isScopeActive('foo'));
-        $c->addScope(new Scope('foo'));
-
-        $this->assertFalse($c->isScopeActive('foo'));
-        $c->enterScope('foo');
-
-        $this->assertTrue($c->isScopeActive('foo'));
-        $c->leaveScope('foo');
-
-        $this->assertFalse($c->isScopeActive('foo'));
+        return $this->__foo_baz;
     }
 
-    public function getLegacyInvalidParentScopes()
+    protected function getCircularService()
     {
-        return array(
-            array(ContainerInterface::SCOPE_PROTOTYPE),
-            array('bar'),
-        );
+        return $this->get('circular');
     }
 
-    public function getLegacyBuiltInScopes()
+    protected function getThrowExceptionService()
     {
-        return array(
-            array(ContainerInterface::SCOPE_CONTAINER),
-            array(ContainerInterface::SCOPE_PROTOTYPE),
-        );
+        throw new \Exception('Something went terribly wrong!');
     }
 
-    protected function getField($obj, $field)
+    protected function getThrowsExceptionOnServiceConfigurationService()
     {
-        $reflection = new \ReflectionProperty($obj, $field);
-        $reflection->setAccessible(true);
+        $this->services['throws_exception_on_service_configuration'] = $instance = new \stdClass();
 
-        return $reflection->getValue($obj);
+        throw new \Exception('Something was terribly wrong while trying to configure the service!');
     }
 
-    public function testAlias()
+    protected function getInternalDependencyService()
     {
-        $c = new ProjectServiceContainer();
+        $this->services['internal_dependency'] = $instance = new \stdClass();
 
-        $this->assertTrue($c->has('alias'));
-        $this->assertSame($c->get('alias'), $c->get('bar'));
-    }
+        $instance->internal = isset($this->services['internal']) ? $this->services['internal'] : $this->getInternalService();
 
-    public function testThatCloningIsNotSupported()
-    {
-        $class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container');
-        $clone = $class->getMethod('__clone');
-        if (PHP_VERSION_ID >= 50400) {
-            $this->assertFalse($class->isCloneable());
-        }
-        $this->assertTrue($clone->isPrivate());
+        return $instance;
     }
 }
 
-class ProjectServiceContainer extends Container
+class LegacyProjectServiceContainer extends Container
 {
     public $__bar;
     public $__foo_bar;
     public $__foo_baz;
-    public $synchronized;
+    public $__internal;
 
     public function __construct()
     {
@@ -719,51 +645,14 @@ class ProjectServiceContainer extends Container
         $this->__bar = new \stdClass();
         $this->__foo_bar = new \stdClass();
         $this->__foo_baz = new \stdClass();
-        $this->synchronized = false;
+        $this->__internal = new \stdClass();
+        $this->privates = array('internal' => true);
         $this->aliases = array('alias' => 'bar');
     }
 
-    protected function getScopedService()
-    {
-        if (!$this->isScopeActive('foo')) {
-            throw new \RuntimeException('Invalid call');
-        }
-
-        return $this->services['scoped'] = $this->scopedServices['foo']['scoped'] = new \stdClass();
-    }
-
-    protected function getScopedFooService()
-    {
-        if (!$this->isScopeActive('foo')) {
-            throw new \RuntimeException('invalid call');
-        }
-
-        return $this->services['scoped_foo'] = $this->scopedServices['foo']['scoped_foo'] = new \stdClass();
-    }
-
-    protected function getScopedSynchronizedFooService()
-    {
-        if (!$this->isScopeActive('foo')) {
-            throw new \RuntimeException('invalid call');
-        }
-
-        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;
-    }
-
-    protected function getInactiveService()
+    protected function getInternalService()
     {
-        throw new InactiveScopeException('request', 'request');
+        return $this->__internal;
     }
 
     protected function getBarService()