public function ContainerTest::testGetSetParameter in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/ContainerTest.php \Symfony\Component\DependencyInjection\Tests\ContainerTest::testGetSetParameter()
@covers Symfony\Component\DependencyInjection\Container::setParameter @covers Symfony\Component\DependencyInjection\Container::getParameter
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Tests/ ContainerTest.php, line 115
Class
Namespace
Symfony\Component\DependencyInjection\TestsCode
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');
}
}