You are here

public function ContainerTest::testGetSetParameter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dependency-injection/Tests/ContainerTest.php \Symfony\Component\DependencyInjection\Tests\ContainerTest::testGetSetParameter()

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

File

vendor/symfony/dependency-injection/Tests/ContainerTest.php, line 115

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');
  }
}