summaryrefslogtreecommitdiffstats
path: root/tests/mocks
diff options
context:
space:
mode:
authorTaufan Aditya <toopay@taufanaditya.com>2012-03-28 11:03:38 +0200
committerTaufan Aditya <toopay@taufanaditya.com>2012-03-28 11:03:38 +0200
commitac5373a8979537f5454af6b911108541140a35d7 (patch)
tree1c44501569f2c55031325aa58d8d6ab9ffa35503 /tests/mocks
parentca16c4ff1aa0cf5ebfbe877e9be755c0b7d2061c (diff)
Adding core and libraries mock classes
Diffstat (limited to 'tests/mocks')
-rw-r--r--tests/mocks/autoloader.php64
-rw-r--r--tests/mocks/core/loader.php3
-rw-r--r--tests/mocks/core/uri.php2
-rw-r--r--tests/mocks/database/.gitkeep0
-rw-r--r--tests/mocks/libraries/parser.php3
-rw-r--r--tests/mocks/libraries/table.php3
-rw-r--r--tests/mocks/libraries/typography.php3
-rw-r--r--tests/mocks/libraries/useragent.php3
8 files changed, 68 insertions, 13 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.");
}
diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php
index 115ccc3de..d4b29bb3d 100644
--- a/tests/mocks/core/loader.php
+++ b/tests/mocks/core/loader.php
@@ -1,8 +1,5 @@
<?php
-require_once 'vfsStream/vfsStream.php';
-require_once BASEPATH.'/core/Loader.php';
-
class Mock_Core_Loader extends CI_Loader {
/**
diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php
index 207c7dc41..b6946091e 100644
--- a/tests/mocks/core/uri.php
+++ b/tests/mocks/core/uri.php
@@ -1,7 +1,5 @@
<?php
-require BASEPATH.'core/URI.php';
-
class Mock_Core_URI extends CI_URI {
public function __construct()
diff --git a/tests/mocks/database/.gitkeep b/tests/mocks/database/.gitkeep
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/mocks/database/.gitkeep
diff --git a/tests/mocks/libraries/parser.php b/tests/mocks/libraries/parser.php
new file mode 100644
index 000000000..81dcfb37e
--- /dev/null
+++ b/tests/mocks/libraries/parser.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_Parser extends CI_Parser {} \ No newline at end of file
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
new file mode 100644
index 000000000..a1e998bb4
--- /dev/null
+++ b/tests/mocks/libraries/table.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_Table extends CI_Table {} \ No newline at end of file
diff --git a/tests/mocks/libraries/typography.php b/tests/mocks/libraries/typography.php
new file mode 100644
index 000000000..0f76c5745
--- /dev/null
+++ b/tests/mocks/libraries/typography.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_Typography extends CI_Typography {} \ No newline at end of file
diff --git a/tests/mocks/libraries/useragent.php b/tests/mocks/libraries/useragent.php
new file mode 100644
index 000000000..c957cde5b
--- /dev/null
+++ b/tests/mocks/libraries/useragent.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_UserAgent extends CI_User_agent {} \ No newline at end of file