[DependencyInjection] fixed Container::getService() when the service is empty (closes #8456)
This commit is contained in:
parent
ba59b1788b
commit
c69410ccde
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user