Browse Source

Fixed autoloader leakage in tests

The autoloader for proxies is now unregistered on shutdown to avoid
having several instances registered at the same time in tests.
Christophe Coevoet 13 years ago
parent
commit
878c2399f1
1 changed files with 13 additions and 2 deletions
  1. 13 2
      src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php

+ 13 - 2
src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php

@@ -24,6 +24,8 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
  */
  */
 class DoctrineBundle extends Bundle
 class DoctrineBundle extends Bundle
 {
 {
+    private $autoloader;
+
     public function build(ContainerBuilder $container)
     public function build(ContainerBuilder $container)
     {
     {
         parent::build($container);
         parent::build($container);
@@ -44,7 +46,7 @@ class DoctrineBundle extends Bundle
             $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
             $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
             $container =& $this->container;
             $container =& $this->container;
 
 
-            spl_autoload_register(function($class) use ($namespace, $dir, &$container) {
+            $this->autoloader = function($class) use ($namespace, $dir, &$container) {
                 if (0 === strpos($class, $namespace)) {
                 if (0 === strpos($class, $namespace)) {
                     $className = substr($class, strlen($namespace) +1);
                     $className = substr($class, strlen($namespace) +1);
                     $file = $dir.DIRECTORY_SEPARATOR.$className.'.php';
                     $file = $dir.DIRECTORY_SEPARATOR.$className.'.php';
@@ -78,7 +80,16 @@ class DoctrineBundle extends Bundle
 
 
                     require $file;
                     require $file;
                 }
                 }
-            });
+            };
+            spl_autoload_register($this->autoloader);
+        }
+    }
+
+    public function shutdown()
+    {
+        if (null !== $this->autoloader) {
+            spl_autoload_unregister($this->autoloader);
+            $this->autoloader = null;
         }
         }
     }
     }
 }
 }