Skip to content

Commit

Permalink
Fix 'undefined index' error, when entering scope recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
ludekstepan authored and fabpot committed Feb 7, 2013
1 parent 10ed567 commit 83e9558
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -334,8 +334,10 @@ public function enterScope($name)
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
Expand Down
32 changes: 32 additions & 0 deletions src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
Expand Up @@ -261,6 +261,38 @@ public function testEnterLeaveScopeWithChildScopes()
$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();
Expand Down

0 comments on commit 83e9558

Please sign in to comment.