diff options
Diffstat (limited to 'tests/mocks/autoloader.php')
-rw-r--r-- | tests/mocks/autoloader.php | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 442389f81..88070e508 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -6,25 +6,73 @@ // // Prototype : // -// include_once('Mock_Core_Common') // Will load ./mocks/core/common.php -// $mock_loader = new Mock_Core_Loader(); // Will load ./mocks/core/loader.php -// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php +// include_once('Mock_Core_Common') // Will load ./mocks/core/common.php +// $mock_loader = new Mock_Core_Loader(); // Will load ./mocks/core/loader.php +// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php +// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php +// and so on... function autoload($class) { - $class = (strpos($class, 'Mock_') === 0) ? str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class) : $class; $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; - $file = $dir.strtolower($class).'.php'; + + $ci_core = array( + 'Benchmark', 'Config', 'Controller', + 'Exceptions', 'Hooks', 'Input', + 'Lang', 'Loader', 'Model', + 'Output', 'Router', 'Security', + 'URI', 'Utf8', + ); + + $ci_libraries = array( + 'Calendar', 'Cart', 'Driver', + 'Email', 'Encrypt', 'Form_validation', + 'Ftp', 'Image_lib', 'Javascript', + 'Log', 'Migration', 'Pagination', + 'Parser', 'Profiler', 'Session', + 'Table', 'Trackback', 'Typography', + 'Unit_test', 'Upload', 'User_agent', + 'Xmlrpc', 'Zip', + ); + + if (strpos($class, 'Mock_') === 0) + { + $class = str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class); + $class = strtolower($class); + } + elseif (strpos($class, 'CI_') === 0) + { + $fragments = explode('_', $class, 2); + $subclass = next($fragments); + + if (in_array($subclass, $ci_core)) + { + $dir = BASEPATH.'core'.DIRECTORY_SEPARATOR; + $class = $subclass; + } + elseif (in_array($subclass, $ci_libraries)) + { + $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; + $class = $subclass; + } + else + { + $class = strtolower($class); + } + } + + $file = $dir.$class.'.php'; if ( ! file_exists($file)) { $trace = debug_backtrace(); - // If the autoload call came from `class_exists`, we skipped - // and return FALSE - if ($trace[2]['function'] == 'class_exists') + // If the autoload call came from `class_exists` or `file_exists`, + // we skipped and return FALSE + if ($trace[2]['function'] == 'class_exists' OR $trace[2]['function'] == 'file_exists') { return FALSE; } + var_dump($file);die; throw new InvalidArgumentException("Unable to load $class."); } |