public function ContainerTest::testGetSetParameter

@covers Symfony\Component\DependencyInjection\Container::setParameter @covers Symfony\Component\DependencyInjection\Container::getParameter

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/ContainerTest.php, line 68

Class

ContainerTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

public function testGetSetParameter() {
  $sc = new Container(new ParameterBag(array(
    'foo' => 'bar',
  )));
  $sc
    ->setParameter('bar', 'foo');
  $this
    ->assertEquals('foo', $sc
    ->getParameter('bar'), '->setParameter() sets the value of a new parameter');
  $sc
    ->setParameter('foo', 'baz');
  $this
    ->assertEquals('baz', $sc
    ->getParameter('foo'), '->setParameter() overrides previously set parameter');
  $sc
    ->setParameter('Foo', 'baz1');
  $this
    ->assertEquals('baz1', $sc
    ->getParameter('foo'), '->setParameter() converts the key to lowercase');
  $this
    ->assertEquals('baz1', $sc
    ->getParameter('FOO'), '->getParameter() converts the key to lowercase');
  try {
    $sc
      ->getParameter('baba');
    $this
      ->fail('->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('\\InvalidArgumentException', $e, '->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
    $this
      ->assertEquals('You have requested a non-existent parameter "baba".', $e
      ->getMessage(), '->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
  }
}