From ca16c4ff1aa0cf5ebfbe877e9be755c0b7d2061c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 15:15:30 +0700 Subject: Adding autoloader and mocks directory --- tests/mocks/autoloader.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/mocks/autoloader.php (limited to 'tests/mocks/autoloader.php') 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 @@ + Date: Wed, 28 Mar 2012 16:03:38 +0700 Subject: Adding core and libraries mock classes --- tests/mocks/autoloader.php | 64 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'tests/mocks/autoloader.php') 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."); } -- cgit v1.2.3-24-g4f1b From e1dc9ea4fcfd4983fa076b70fe631166a95d0b68 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:49:49 +0700 Subject: Remove include or require declaration from all helpers test --- tests/mocks/autoloader.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 88070e508..bf3fbc508 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -6,8 +6,7 @@ // // Prototype : // -// include_once('Mock_Core_Common') // Will load ./mocks/core/common.php -// $mock_loader = new Mock_Core_Loader(); // Will load ./mocks/core/loader.php +// include_once('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... -- cgit v1.2.3-24-g4f1b From bdb84af43792f507eaab5ab0c4b3ec1be17a1a54 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 17:03:59 +0700 Subject: Remove debugging line --- tests/mocks/autoloader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index bf3fbc508..dd5929206 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -71,7 +71,6 @@ function autoload($class) { return FALSE; } - var_dump($file);die; throw new InvalidArgumentException("Unable to load $class."); } -- cgit v1.2.3-24-g4f1b From f4c6c9b3061b464c959b6409f962228959f35287 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 23:24:09 +0700 Subject: DB Drivers test --- tests/mocks/autoloader.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index dd5929206..22448139e 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -53,13 +53,24 @@ function autoload($class) $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; $class = $subclass; } + elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3) + { + $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; + $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR; + $file = $dir.$m[1].'_'.$m[2].'.php'; + } + elseif (strpos($class, 'CI_DB') === 0) + { + $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR; + $file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php'; + } else { $class = strtolower($class); } } - $file = $dir.$class.'.php'; + $file = (isset($file)) ? $file : $dir.$class.'.php'; if ( ! file_exists($file)) { @@ -71,7 +82,7 @@ function autoload($class) { return FALSE; } - + var_dump($file); throw new InvalidArgumentException("Unable to load $class."); } -- cgit v1.2.3-24-g4f1b From 61ff054fb905f0514b942bf3e70a6c882bd64f7a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:23:56 +0700 Subject: Adding schema and initial Query Builder code coverage --- tests/mocks/autoloader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 22448139e..f1bdb5d6f 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -62,7 +62,7 @@ function autoload($class) elseif (strpos($class, 'CI_DB') === 0) { $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR; - $file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php'; + $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php'; } else { @@ -82,7 +82,7 @@ function autoload($class) { return FALSE; } - var_dump($file); + throw new InvalidArgumentException("Unable to load $class."); } -- cgit v1.2.3-24-g4f1b From 12f4c9b25ff366db05ebc4fa13b8f7ab0b1e3dae Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 18:48:45 +0700 Subject: Clean up autoloader annotation --- tests/mocks/autoloader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index f1bdb5d6f..92c9bea59 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -6,7 +6,6 @@ // // Prototype : // -// include_once('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... -- cgit v1.2.3-24-g4f1b From 6c7526c95b3fbd502dc8105a67fd38da793caa4e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 27 May 2012 13:51:27 +0700 Subject: Continuation for Security and Table code-coverage, add coverage report to travis --- tests/mocks/autoloader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 92c9bea59..441c88944 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -22,7 +22,7 @@ function autoload($class) ); $ci_libraries = array( - 'Calendar', 'Cart', 'Driver', + 'Calendar', 'Cart', 'Driver_Library', 'Email', 'Encrypt', 'Form_validation', 'Ftp', 'Image_lib', 'Javascript', 'Log', 'Migration', 'Pagination', @@ -50,7 +50,7 @@ function autoload($class) elseif (in_array($subclass, $ci_libraries)) { $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; - $class = $subclass; + $class = ($subclass == 'Driver_Library') ? 'Driver' : $subclass; } elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3) { -- cgit v1.2.3-24-g4f1b From d6d1150959c95e43d310d0bc45f8bd674ff6460c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:55 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /tests --- tests/mocks/autoloader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 441c88944..ff2196d4e 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -50,9 +50,9 @@ function autoload($class) elseif (in_array($subclass, $ci_libraries)) { $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; - $class = ($subclass == 'Driver_Library') ? 'Driver' : $subclass; + $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass; } - elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3) + elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3) { $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR; @@ -77,7 +77,7 @@ function autoload($class) // 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') + if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists') { return FALSE; } -- cgit v1.2.3-24-g4f1b From fc11dcc82cefa7299e6f8c74d0e005ebb6fa568c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Jun 2012 16:39:19 +0300 Subject: Alter SQLite3's version() method and clear some spaces --- tests/mocks/autoloader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/mocks/autoloader.php') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index ff2196d4e..90aabcbe6 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -7,9 +7,9 @@ // Prototype : // // $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 +// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php // and so on... -function autoload($class) +function autoload($class) { $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; @@ -75,13 +75,13 @@ function autoload($class) { $trace = debug_backtrace(); - // If the autoload call came from `class_exists` or `file_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; } - + throw new InvalidArgumentException("Unable to load $class."); } -- cgit v1.2.3-24-g4f1b