You are here

public function ContainerTest::testEnterLeaveCurrentScope in Service Container 7

Same name and namespace in other branches
  1. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/ContainerTest.php \Symfony\Component\DependencyInjection\Tests\ContainerTest::testEnterLeaveCurrentScope()

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/ContainerTest.php, line 314

Class

ContainerTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

public function testEnterLeaveCurrentScope() {
  $container = new ProjectServiceContainer();
  $container
    ->addScope(new Scope('foo'));
  $container
    ->enterScope('foo');
  $scoped1 = $container
    ->get('scoped');
  $scopedFoo1 = $container
    ->get('scoped_foo');
  $container
    ->enterScope('foo');
  $scoped2 = $container
    ->get('scoped');
  $scoped3 = $container
    ->get('SCOPED');
  $scopedFoo2 = $container
    ->get('scoped_foo');
  $container
    ->leaveScope('foo');
  $scoped4 = $container
    ->get('scoped');
  $scopedFoo3 = $container
    ->get('scoped_foo');
  $this
    ->assertNotSame($scoped1, $scoped2);
  $this
    ->assertSame($scoped2, $scoped3);
  $this
    ->assertSame($scoped1, $scoped4);
  $this
    ->assertNotSame($scopedFoo1, $scopedFoo2);
  $this
    ->assertSame($scopedFoo1, $scopedFoo3);
}