Fix 'undefined index' error, when entering scope recursively

This commit is contained in:
Ludek Stepan 2012-11-26 15:59:46 +01:00 committed by Fabien Potencier
parent 10ed567f60
commit 83e95586e7
2 changed files with 36 additions and 2 deletions

View File

@ -334,8 +334,10 @@ class Container implements IntrospectableContainerInterface
unset($this->scopedServices[$name]);
foreach ($this->scopeChildren[$name] as $child) {
$services[$child] = $this->scopedServices[$child];
unset($this->scopedServices[$child]);
if (isset($this->scopedServices[$child])) {
$services[$child] = $this->scopedServices[$child];
unset($this->scopedServices[$child]);
}
}
// update global map

View File

@ -261,6 +261,38 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($container->has('a'));
}
public function testEnterScopeRecursivelyWithInactiveChildScopes()
{
$container = new Container();
$container->addScope(new Scope('foo'));
$container->addScope(new Scope('bar', 'foo'));
$this->assertFalse($container->isScopeActive('foo'));
$container->enterScope('foo');
$this->assertTrue($container->isScopeActive('foo'));
$this->assertFalse($container->isScopeActive('bar'));
$this->assertFalse($container->has('a'));
$a = new \stdClass();
$container->set('a', $a, 'foo');
$services = $this->getField($container, 'scopedServices');
$this->assertTrue(isset($services['foo']['a']));
$this->assertSame($a, $services['foo']['a']);
$this->assertTrue($container->has('a'));
$container->enterScope('foo');
$services = $this->getField($container, 'scopedServices');
$this->assertFalse(isset($services['a']));
$this->assertTrue($container->isScopeActive('foo'));
$this->assertFalse($container->isScopeActive('bar'));
$this->assertFalse($container->has('a'));
}
public function testLeaveScopeNotActive()
{
$container = new Container();