public function ContainerTest::testGetThrowServiceNotFoundException 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::testGetThrowServiceNotFoundException()
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Tests/ ContainerTest.php, line 238
Class
Namespace
Symfony\Component\DependencyInjection\TestsCode
public function testGetThrowServiceNotFoundException() {
$sc = new ProjectServiceContainer();
$sc
->set('foo', $foo = new \stdClass());
$sc
->set('bar', $foo = new \stdClass());
$sc
->set('baz', $foo = new \stdClass());
try {
$sc
->get('foo1');
$this
->fail('->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
} catch (\Exception $e) {
$this
->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException', $e, '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
$this
->assertEquals('You have requested a non-existent service "foo1". Did you mean this: "foo"?', $e
->getMessage(), '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException with some advices');
}
try {
$sc
->get('bag');
$this
->fail('->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
} catch (\Exception $e) {
$this
->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException', $e, '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException if the key does not exist');
$this
->assertEquals('You have requested a non-existent service "bag". Did you mean one of these: "bar", "baz"?', $e
->getMessage(), '->get() throws an Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException with some advices');
}
}