summaryrefslogtreecommitdiffstats
path: root/tests/mocks/autoloader.php
diff options
context:
space:
mode:
authorTaufan Aditya <toopay@taufanaditya.com>2012-03-28 10:15:30 +0200
committerTaufan Aditya <toopay@taufanaditya.com>2012-03-28 10:15:30 +0200
commitca16c4ff1aa0cf5ebfbe877e9be755c0b7d2061c (patch)
tree3d4fdf3ef62e215f2040992196bc041a91c97e90 /tests/mocks/autoloader.php
parent67c287192b5ff414753ae50a834932f676a0db9e (diff)
Adding autoloader and mocks directory
Diffstat (limited to 'tests/mocks/autoloader.php')
-rw-r--r--tests/mocks/autoloader.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
new file mode 100644
index 000000000..442389f81
--- /dev/null
+++ b/tests/mocks/autoloader.php
@@ -0,0 +1,33 @@
+<?php
+
+// This autoloader provide convinient way to working with mock object
+// make the test looks natural. This autoloader support cascade file loading as well
+// within mocks directory.
+//
+// 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
+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';
+
+ 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')
+ {
+ return FALSE;
+ }
+
+ throw new InvalidArgumentException("Unable to load $class.");
+ }
+
+ include_once($file);
+} \ No newline at end of file