public function ContainerBuilderTest::testLegacySynchronizedServiceWithScopes in Service Container 7
Same name and namespace in other branches
- 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php \Symfony\Component\DependencyInjection\Tests\ContainerBuilderTest::testLegacySynchronizedServiceWithScopes()
@group legacy
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Tests/ ContainerBuilderTest.php, line 755
Class
Namespace
Symfony\Component\DependencyInjection\TestsCode
public function testLegacySynchronizedServiceWithScopes() {
$this
->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = new ContainerBuilder();
$container
->addScope(new Scope('foo'));
$container
->register('baz', 'BazClass')
->setSynthetic(true)
->setSynchronized(true)
->setScope('foo');
$container
->register('bar', 'BarClass')
->addMethodCall('setBaz', array(
new Reference('baz', ContainerInterface::NULL_ON_INVALID_REFERENCE, false),
));
$container
->compile();
$container
->enterScope('foo');
$container
->set('baz', $outerBaz = new \BazClass(), 'foo');
$this
->assertSame($outerBaz, $container
->get('bar')
->getBaz());
$container
->enterScope('foo');
$container
->set('baz', $innerBaz = new \BazClass(), 'foo');
$this
->assertSame($innerBaz, $container
->get('bar')
->getBaz());
$container
->leaveScope('foo');
$this
->assertNotSame($innerBaz, $container
->get('bar')
->getBaz());
$this
->assertSame($outerBaz, $container
->get('bar')
->getBaz());
$container
->leaveScope('foo');
}