Merge remote branch 'vicb/bundle_inheritance'

* vicb/bundle_inheritance:
  [Kernel] Fix bundle inheritance
This commit is contained in:
Fabien Potencier 2011-04-06 11:29:05 +02:00
commit ae218d202e
2 changed files with 20 additions and 0 deletions

View File

@ -369,6 +369,7 @@ abstract class Kernel implements KernelInterface
*
* @throws \LogicException if two bundles share a common name
* @throws \LogicException if a bundle tries to extend a non-registered bundle
* @throws \LogicException if a bundle tries to extend itself
* @throws \LogicException if two bundles extend the same ancestor
*/
protected function initializeBundles()
@ -389,6 +390,9 @@ abstract class Kernel implements KernelInterface
if (isset($directChildren[$parentName])) {
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
}
if ($parentName == $name) {
throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
}
$directChildren[$parentName] = $name;
} else {
$topMostBundles[$name] = $bundle;

View File

@ -620,6 +620,22 @@ EOF;
$kernel->initializeBundles();
}
/**
* @expectedException \LogicException
*/
public function testInitializeBundleThrowsExceptionWhenABundleExtendsItself()
{
$circularRef = $this->getBundle(null, 'CircularRefBundle', 'CircularRefBundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($circularRef)))
;
$kernel->initializeBundles();
}
protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null)
{
$bundle = $this