Allow running tests without surrounding framework

This commit is contained in:
Jordi Boggiano 2012-04-13 14:55:22 +02:00
parent ef40b1c3c2
commit 1e1a35aed5

View File

@ -12,6 +12,22 @@ if ((!$loader = includeIfExists(__DIR__.'/../../../../../.composer/autoload.php'
'php composer.phar install'.PHP_EOL);
}
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
spl_autoload_register(function($class) {
if (0 === strpos($class, 'Nelmio\ApiDocBundle\\')) {
$path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
if (!stream_resolve_include_path($path)) {
return false;
}
require_once $path;
return true;
}
});
return $loader;
use Doctrine\Common\Annotations\AnnotationRegistry;
AnnotationRegistry::registerLoader(function($class) {
if (strpos($class, 'Nelmio\ApiDocBundle\Annotation\\') === 0) {
$path = __DIR__.'/../'.str_replace('\\', '/', substr($class, strlen('Nelmio\ApiDocBundle\\'))) .'.php';
require_once $path;
}
return class_exists($class, false);
});