You are here

public function ParameterBagTest::testGetThrowParameterNotFoundException in Service Container 7.2

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

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/ParameterBag/ParameterBagTest.php, line 87

Class

ParameterBagTest

Namespace

Symfony\Component\DependencyInjection\Tests\ParameterBag

Code

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