From bbb47168da7c36371eb2b921f720e9bcbe153cf3 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 3 Jan 2013 18:43:08 +0100 Subject: [PATCH] [task/fix-test-autoloader] Fix autoloader to support failing/erroring tests. Before showing error output PHPUnit 3.7.x calls class_exists() on some PHPUnit Extension class names that may not exist. Calling class_exists() already triggers the autoload function in which require() then obviously fails. We now check whether a file is includable by simply looping over all possible include directories. --- tests/bootstrap.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index eb7136b8..13a8e81b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -9,14 +9,34 @@ // class files of phpseclib require() other dependencies. set_include_path(implode(PATH_SEPARATOR, array( dirname(__FILE__) . '/../phpseclib/', + dirname(__FILE__) . '/', get_include_path(), ))); +function phpseclib_is_includable($suffix) +{ + foreach (explode(PATH_SEPARATOR, get_include_path()) as $prefix) + { + $ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR; + $file = $prefix . $ds . $suffix; + + if (file_exists($file)) + { + return true; + } + } + + return false; +} + function phpseclib_autoload($class) { $file = str_replace('_', '/', $class) . '.php'; - require $file; + if (phpseclib_is_includable($file)) + { + require $file; + } } spl_autoload_register('phpseclib_autoload');