You are here

public function ParameterBagTest::testGetSet in Zircon Profile 8

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

@covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::get @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::set

File

vendor/symfony/dependency-injection/Tests/ParameterBag/ParameterBagTest.php, line 65

Class

ParameterBagTest

Namespace

Symfony\Component\DependencyInjection\Tests\ParameterBag

Code

public function testGetSet() {
  $bag = new ParameterBag(array(
    'foo' => 'bar',
  ));
  $bag
    ->set('bar', 'foo');
  $this
    ->assertEquals('foo', $bag
    ->get('bar'), '->set() sets the value of a new parameter');
  $bag
    ->set('foo', 'baz');
  $this
    ->assertEquals('baz', $bag
    ->get('foo'), '->set() overrides previously set parameter');
  $bag
    ->set('Foo', 'baz1');
  $this
    ->assertEquals('baz1', $bag
    ->get('foo'), '->set() converts the key to lowercase');
  $this
    ->assertEquals('baz1', $bag
    ->get('FOO'), '->get() converts the key to lowercase');
  try {
    $bag
      ->get('baba');
    $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 "baba".', $e
      ->getMessage(), '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ParameterNotFoundException if the key does not exist');
  }
}