[DependencyInjection] fixed Container::getService() when the service is empty (closes #8456)

This commit is contained in:
Fabien Potencier 2010-03-25 14:04:48 +01:00
parent ba59b1788b
commit c69410ccde
2 changed files with 15 additions and 1 deletions

View File

@ -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)))); 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(); return $this->$method();
} }

View File

@ -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 class ProjectServiceContainer extends Container