From c69410ccdeaaa8c701bf1db1a527f71e00c2e1b6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 25 Mar 2010 14:04:48 +0100 Subject: [PATCH] [DependencyInjection] fixed Container::getService() when the service is empty (closes #8456) --- .../Components/DependencyInjection/Container.php | 2 +- .../DependencyInjection/ContainerTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Components/DependencyInjection/Container.php b/src/Symfony/Components/DependencyInjection/Container.php index 95ec411821..c6a011a218 100644 --- a/src/Symfony/Components/DependencyInjection/Container.php +++ b/src/Symfony/Components/DependencyInjection/Container.php @@ -193,7 +193,7 @@ class Container implements ContainerInterface, \ArrayAccess throw new \InvalidArgumentException(sprintf('A service id should be a string (%s given).', str_replace("\n", '', var_export($id, true)))); } - if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) + if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service') && 'getService' !== $method) { return $this->$method(); } diff --git a/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php b/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php index 4fb0838e89..ff3baf28f6 100644 --- a/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php +++ b/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php @@ -176,6 +176,20 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { } } + + public function testGetService() + { + $sc = new Container(); + + try + { + $sc->getService(''); + $this->fail('->getService() throws a \InvalidArgumentException exception if the service is empty'); + } + catch (\InvalidArgumentException $e) + { + } + } } class ProjectServiceContainer extends Container