[DependencyInjection] reverted 2ac6faaa0b
This commit is contained in:
parent
9ebfdf24a5
commit
1683f46279
|
@ -193,16 +193,16 @@ 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') && 'getService' !== $method)
|
||||
{
|
||||
return $this->$method();
|
||||
}
|
||||
|
||||
if (isset($this->services[$id]))
|
||||
{
|
||||
return $this->services[$id];
|
||||
}
|
||||
|
||||
if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service') && 'getService' !== $method)
|
||||
{
|
||||
return $this->$method();
|
||||
}
|
||||
|
||||
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior)
|
||||
{
|
||||
throw new \InvalidArgumentException(sprintf('The service "%s" does not exist.', $id));
|
||||
|
|
|
@ -126,7 +126,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method');
|
||||
|
||||
$sc->setService('bar', $bar = new \stdClass());
|
||||
$this->assertNotEquals(spl_object_hash($sc->getService('bar')), spl_object_hash($bar), '->getService() prefers to return a service defined with a getXXXService() method than one defined with setService()');
|
||||
$this->assertEquals(spl_object_hash($sc->getService('bar')), spl_object_hash($bar), '->getService() prefers to return a service defined with a getXXXService() method than one defined with setService()');
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -57,4 +57,17 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
public function testOverrideServiceWhenUsingADumpedContainer()
|
||||
{
|
||||
require_once self::$fixturesPath.'/php/services9.php';
|
||||
require_once self::$fixturesPath.'/includes/foo.php';
|
||||
|
||||
$container = new \ProjectServiceContainer();
|
||||
$container->setService('bar', $bar = new \stdClass());
|
||||
$container->setParameter('foo_bar', 'foo_bar');
|
||||
|
||||
$this->assertEquals($bar, $container->getBarService(), '->setService() overrides an already defined service');
|
||||
$this->assertEquals($bar, $container->getService('bar'), '->setService() overrides an already defined service');
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue