[ClassLoader] Fixed state when trait_exists doesn't exists

This commit is contained in:
Josef Cech 2011-09-25 13:13:28 +02:00
parent 369d4da4eb
commit 85ed5c67dc
3 changed files with 10 additions and 2 deletions

View File

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

View File

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

View File

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