You are here

public function ContainerBuilderTest::testLegacySynchronizedServiceWithScopes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dependency-injection/Tests/ContainerBuilderTest.php \Symfony\Component\DependencyInjection\Tests\ContainerBuilderTest::testLegacySynchronizedServiceWithScopes()

@group legacy

File

vendor/symfony/dependency-injection/Tests/ContainerBuilderTest.php, line 752

Class

ContainerBuilderTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

public function testLegacySynchronizedServiceWithScopes() {
  $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');
}