You are here

public function ContainerTest::testLeaveScopeNotActive in Service Container 7.2

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

File

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

Class

ContainerTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

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