瀏覽代碼

Merge remote branch 'vicb/bundle_inheritance'

* vicb/bundle_inheritance:
  [Kernel] Fix bundle inheritance
Fabien Potencier 14 年之前
父節點
當前提交
ae218d202e
共有 2 個文件被更改,包括 20 次插入0 次删除
  1. 4 0
      src/Symfony/Component/HttpKernel/Kernel.php
  2. 16 0
      tests/Symfony/Tests/Component/HttpKernel/KernelTest.php

+ 4 - 0
src/Symfony/Component/HttpKernel/Kernel.php

@@ -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;

+ 16 - 0
tests/Symfony/Tests/Component/HttpKernel/KernelTest.php

@@ -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