From d6025619a4ece05fddd8c2b18bdd81156b5681f4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 4 Apr 2020 11:26:20 +0900 Subject: [PATCH] Merge branch 'cedriclange-master' See https://github.com/kenjis/ci-phpunit-test/pull/327 --- .../tests/_ci_phpunit_test/CIPHPUnitTest.php | 24 +++++++++++++++++++ .../tests/_ci_phpunit_test/functions.php | 1 + 2 files changed, 25 insertions(+) diff --git a/application/tests/_ci_phpunit_test/CIPHPUnitTest.php b/application/tests/_ci_phpunit_test/CIPHPUnitTest.php index e166693b..132bbb6b 100644 --- a/application/tests/_ci_phpunit_test/CIPHPUnitTest.php +++ b/application/tests/_ci_phpunit_test/CIPHPUnitTest.php @@ -11,6 +11,7 @@ class CIPHPUnitTest { private static $loader_class = 'CI_Loader'; + private static $config_class = 'CI_Config'; private static $controller_class; private static $autoload_dirs; @@ -98,6 +99,7 @@ public static function init(array $autoload_dirs = null) // This code is here, not to cause errors with HMVC self::replaceLoader(); + self::replaceConfig(); // Restore $_SERVER. We need this for NetBeans $_SERVER = $_server_backup; @@ -185,6 +187,22 @@ protected static function replaceLoader() self::loadLoader(); } + protected static function replaceConfig() + { + $my_config_file = + APPPATH . 'core/' . config_item('subclass_prefix') . 'Config.php'; + + if (file_exists($my_config_file)) + { + self::$config_class = config_item('subclass_prefix') . 'Config'; + if ( ! class_exists(self::$config_class)) + { + require $my_config_file; + } + } + self::loadConfig(); + } + protected static function replaceHelpers() { $helpers = ['url_helper', 'download_helper']; @@ -220,4 +238,10 @@ public static function loadLoader() $loader = new self::$loader_class; load_class_instance('Loader', $loader); } + + public static function loadConfig() + { + $config= new self::$config_class; + load_class_instance('Config', $config); + } } diff --git a/application/tests/_ci_phpunit_test/functions.php b/application/tests/_ci_phpunit_test/functions.php index f44fb2ad..f6d861f7 100644 --- a/application/tests/_ci_phpunit_test/functions.php +++ b/application/tests/_ci_phpunit_test/functions.php @@ -74,6 +74,7 @@ function reset_instance() CIPHPUnitTestSuperGlobal::set_Global('LANG', $LANG); CIPHPUnitTest::loadLoader(); + CIPHPUnitTest::loadConfig(); // Remove CodeIgniter instance $CI = new CIPHPUnitTestNullCodeIgniter();