浏览代码

[ClassLoader] Fixed state when trait_exists doesn't exists

Josef Cech 13 年之前
父节点
当前提交
85ed5c67dc

+ 1 - 1
src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

@@ -84,7 +84,7 @@ class ClassCollectionLoader
         $files = array();
         $content = '';
         foreach ($classes as $class) {
-            if (!class_exists($class) && !interface_exists($class) && function_exists('trait_exists') && !trait_exists($class)) {
+            if (!class_exists($class) && !interface_exists($class) && (!function_exists('trait_exists') || !trait_exists($class))) {
                 throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
             }
 

+ 1 - 1
src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php

@@ -54,7 +54,7 @@ class DebugUniversalClassLoader extends UniversalClassLoader
         if ($file = $this->findFile($class)) {
             require $file;
 
-            if (!class_exists($class, false) && !interface_exists($class, false) && function_exists('trait_exists') && !trait_exists($class)) {
+            if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class))) {
                 throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
             }
         }

+ 8 - 0
tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php

@@ -63,4 +63,12 @@ EOF;
 
         $this->assertEquals($expected, ClassCollectionLoader::fixNamespaceDeclarations($source));
     }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testUnableToLoadClassException()
+    {
+        ClassCollectionLoader::load(array('SomeNotExistingClass'), '', 'foo', false);
+    }
 }