You are here

public function ParameterBagTest::testGetSet 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::testGetSet()

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

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/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');
  }
}