From 6030719346e9b0eb0e0ea99c679cadeb1fe4afde Mon Sep 17 00:00:00 2001 From: dchill42 Date: Mon, 27 Aug 2012 23:59:31 -0400 Subject: Improved VFS usage in Loader and Config units, added Loader driver test, and moved config load testing to Config unit Signed-off-by: dchill42 --- tests/mocks/core/loader.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'tests/mocks/core') diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index 53d88d55b..e28650dba 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -5,27 +5,31 @@ class Mock_Core_Loader extends CI_Loader { /** * Since we use paths to load up models, views, etc, we need the ability to * mock up the file system so when core tests are run, we aren't mucking - * in the application directory. this will give finer grained control over - * these tests. So yeah, while this looks odd, I need to overwrite protected - * class vars in the loader. So here we go... + * in the application directory. This will give finer grained control over + * these tests. Also, by mocking the system directory, we eliminate dependency + * on any other classes so errors in libraries, helpers, etc. don't give false + * negatives for the actual loading process. So yeah, while this looks odd, + * I need to overwrite protected class vars in the loader. So here we go... * * @covers CI_Loader::__construct() */ public function __construct() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('application')); + // Create VFS tree of loader locations + $this->root = vfsStream::setup(); + $this->app_root = vfsStream::newDirectory('application')->at($this->root); + $this->base_root = vfsStream::newDirectory('system')->at($this->root); - $this->models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot()); - $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot()); - $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot()); - $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot()); + // Get VFS app and base path URLs + $this->app_path = vfsStream::url('application').'/'; + $this->base_path = vfsStream::url('system').'/'; + // Set loader paths with VFS URLs $this->_ci_ob_level = ob_get_level(); - $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH); - $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH); - $this->_ci_model_paths = array(vfsStream::url('application').'/'); - $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE); + $this->_ci_library_paths = array($this->app_path, $this->base_path); + $this->_ci_helper_paths = array($this->app_path, $this->base_path); + $this->_ci_model_paths = array($this->app_path); + $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 60d100f0fde3fba4fa4015f44f490b7ecac16138 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Wed, 29 Aug 2012 12:58:26 -0400 Subject: Added autoloader unit test with minor supporting change in Loader Signed-off-by: dchill42 --- tests/mocks/core/loader.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/mocks/core') diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index e28650dba..c0e02139e 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -30,6 +30,15 @@ class Mock_Core_Loader extends CI_Loader { $this->_ci_helper_paths = array($this->app_path, $this->base_path); $this->_ci_model_paths = array($this->app_path); $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); + $this->_ci_autoloader_path = $this->app_path; + } + + /** + * Give public access to _ci_autoloader for testing + */ + public function autoload() + { + $this->_ci_autoloader(); } } -- cgit v1.2.3-24-g4f1b From eeb6a480a4a25b7fe96e9ba0cf3aef273fd13c67 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Thu, 30 Aug 2012 09:46:20 -0400 Subject: Better way - autoloader uses first config path Signed-off-by: dchill42 --- tests/mocks/core/loader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/mocks/core') diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index c0e02139e..9eb78253b 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -30,7 +30,6 @@ class Mock_Core_Loader extends CI_Loader { $this->_ci_helper_paths = array($this->app_path, $this->base_path); $this->_ci_model_paths = array($this->app_path); $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); - $this->_ci_autoloader_path = $this->app_path; } /** -- cgit v1.2.3-24-g4f1b From 7ecc5cda6647a4b316b44dc40d5925d9ef63c908 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Fri, 12 Oct 2012 16:25:51 -0400 Subject: Integrated vfsStream better and made paths constants VFS-based Signed-off-by: dchill42 --- tests/mocks/core/common.php | 26 +++++++++++++++++++++++++- tests/mocks/core/loader.php | 30 ------------------------------ 2 files changed, 25 insertions(+), 31 deletions(-) (limited to 'tests/mocks/core') diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index a655ee1db..b001074c8 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -39,6 +39,30 @@ if ( ! function_exists('config_item')) } } +if ( ! function_exists('get_mimes')) +{ + /** + * Returns the MIME types array from config/mimes.php + * + * @return array + */ + function &get_mimes() + { + static $_mimes = array(); + + if (empty($_mimes)) + { + $path = realpath(PROJECT_BASE.'application/config/mimes.php'); + if (is_file($path)) + { + $_mimes = include($path); + } + } + + return $_mimes; + } +} + // -------------------------------------------------------------------- if ( ! function_exists('load_class')) @@ -166,4 +190,4 @@ if ( ! function_exists('set_status_header')) { return TRUE; } -} \ No newline at end of file +} diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index 9eb78253b..7ea4da369 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -2,36 +2,6 @@ class Mock_Core_Loader extends CI_Loader { - /** - * Since we use paths to load up models, views, etc, we need the ability to - * mock up the file system so when core tests are run, we aren't mucking - * in the application directory. This will give finer grained control over - * these tests. Also, by mocking the system directory, we eliminate dependency - * on any other classes so errors in libraries, helpers, etc. don't give false - * negatives for the actual loading process. So yeah, while this looks odd, - * I need to overwrite protected class vars in the loader. So here we go... - * - * @covers CI_Loader::__construct() - */ - public function __construct() - { - // Create VFS tree of loader locations - $this->root = vfsStream::setup(); - $this->app_root = vfsStream::newDirectory('application')->at($this->root); - $this->base_root = vfsStream::newDirectory('system')->at($this->root); - - // Get VFS app and base path URLs - $this->app_path = vfsStream::url('application').'/'; - $this->base_path = vfsStream::url('system').'/'; - - // Set loader paths with VFS URLs - $this->_ci_ob_level = ob_get_level(); - $this->_ci_library_paths = array($this->app_path, $this->base_path); - $this->_ci_helper_paths = array($this->app_path, $this->base_path); - $this->_ci_model_paths = array($this->app_path); - $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); - } - /** * Give public access to _ci_autoloader for testing */ -- cgit v1.2.3-24-g4f1b From 4f42be55dc5ca3141f3d93f7f59989d3e52bc5a3 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sun, 21 Oct 2012 21:31:19 -0400 Subject: Raised CI_Loader test coverage to 93% Signed-off-by: dchill42 --- tests/mocks/core/common.php | 7 ++++--- tests/mocks/core/loader.php | 13 ------------- 2 files changed, 4 insertions(+), 16 deletions(-) delete mode 100644 tests/mocks/core/loader.php (limited to 'tests/mocks/core') diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index b001074c8..9289b2716 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -170,9 +170,10 @@ if ( ! function_exists('is_really_writable')) if ( ! function_exists('is_loaded')) { - function is_loaded() + function &is_loaded() { - throw new Exception('Bad Isolation: mock up environment'); + $loaded = array(); + return $loaded; } } @@ -190,4 +191,4 @@ if ( ! function_exists('set_status_header')) { return TRUE; } -} +} \ No newline at end of file diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php deleted file mode 100644 index 7ea4da369..000000000 --- a/tests/mocks/core/loader.php +++ /dev/null @@ -1,13 +0,0 @@ -_ci_autoloader(); - } - -} -- cgit v1.2.3-24-g4f1b