You are here

public function ContainerTest::testGetThrowServiceNotFoundException 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::testGetThrowServiceNotFoundException()

File

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

Class

ContainerTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

public function testGetThrowServiceNotFoundException() {
  $sc = new ProjectServiceContainer();
  $sc
    ->set('foo', $foo = new \stdClass());
  $sc
    ->set('bar', $foo = new \stdClass());
  $sc
    ->set('baz', $foo = new \stdClass());
  try {
    $sc
      ->get('foo1');
    $this
      ->fail('->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException', $e, '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
    $this
      ->assertEquals('You have requested a non-existent service "foo1". Did you mean this: "foo"?', $e
      ->getMessage(), '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException with some advices');
  }
  try {
    $sc
      ->get('bag');
    $this
      ->fail('->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException', $e, '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
    $this
      ->assertEquals('You have requested a non-existent service "bag". Did you mean one of these: "bar", "baz"?', $e
      ->getMessage(), '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException with some advices');
  }
}