@@ -22,12 +22,7 @@ public static function init()
2222 ];
2323 $ _SERVER ['argc ' ] = 2 ;
2424
25- require __DIR__ . '/CIPHPUnitTestCase.php ' ;
26- require __DIR__ . '/CIPHPUnitTestRequest.php ' ;
27- require __DIR__ . '/CIPHPUnitTestDouble.php ' ;
28- require __DIR__ . '/exceptions/CIPHPUnitTestRedirectException.php ' ;
29- require __DIR__ . '/exceptions/CIPHPUnitTestShow404Exception.php ' ;
30- require __DIR__ . '/exceptions/CIPHPUnitTestShowErrorException.php ' ;
25+ self ::loadCIPHPUnitTestClasses ();
3126
3227 // Replace a few Common functions
3328 require __DIR__ . '/replacing/core/Common.php ' ;
@@ -36,15 +31,8 @@ public static function init()
3631 // Load new functions of CIPHPUnitTest
3732 require __DIR__ . '/functions.php ' ;
3833
39- // Replace Loader
40- require __DIR__ . '/replacing/core/Loader.php ' ;
41- $ my_loader_file = APPPATH . 'core/ ' . config_item ('subclass_prefix ' ) . 'Loader.php ' ;
42- if (file_exists ($ my_loader_file ))
43- {
44- self ::$ loader_class = config_item ('subclass_prefix ' ) . 'Loader ' ;
45- require $ my_loader_file ;
46- }
47- self ::loadLoader ();
34+ self ::replaceLoader ();
35+ self ::replaceHelpers ();
4836
4937 // Load autoloader for CIPHPUnitTest
5038 require __DIR__ . '/autoloader.php ' ;
@@ -65,9 +53,7 @@ public static function init()
6553 // If controller Welcome is called in bootstrap, we can't test
6654 // the same name sub controller Welcome even when we use
6755 // `@runInSeparateProcess` and `@preserveGlobalState disabled`
68- ob_start ();
6956 require_once BASEPATH . 'core/CodeIgniter.php ' ;
70- ob_end_clean ();
7157 } catch (CIPHPUnitTestShow404Exception $ e ) {
7258 // Catch 404 exception
7359 new CI_Controller ();
@@ -77,6 +63,75 @@ public static function init()
7763
7864 // Restore $_SERVER
7965 $ _SERVER = $ _server_backup ;
66+
67+ if (isset (TestCase::$ enable_patcher ) && TestCase::$ enable_patcher )
68+ {
69+ self ::enablePatcher ();
70+ }
71+ }
72+
73+ protected static function replaceLoader ()
74+ {
75+ require __DIR__ . '/replacing/core/Loader.php ' ;
76+ $ my_loader_file = APPPATH . 'core/ ' . config_item ('subclass_prefix ' ) . 'Loader.php ' ;
77+ if (file_exists ($ my_loader_file ))
78+ {
79+ self ::$ loader_class = config_item ('subclass_prefix ' ) . 'Loader ' ;
80+ require $ my_loader_file ;
81+ }
82+ self ::loadLoader ();
83+ }
84+
85+ protected static function replaceHelpers ()
86+ {
87+ $ my_helper_file = APPPATH . 'helpers/ ' . config_item ('subclass_prefix ' ) . 'url_helper.php ' ;
88+ if (file_exists ($ my_helper_file ))
89+ {
90+ require $ my_helper_file ;
91+ }
92+ require __DIR__ . '/replacing/helpers/url_helper.php ' ;
93+ }
94+
95+ protected static function loadCIPHPUnitTestClasses ()
96+ {
97+ require __DIR__ . '/CIPHPUnitTestCase.php ' ;
98+ require __DIR__ . '/CIPHPUnitTestRequest.php ' ;
99+ require __DIR__ . '/CIPHPUnitTestDouble.php ' ;
100+ require __DIR__ . '/exceptions/CIPHPUnitTestRedirectException.php ' ;
101+ require __DIR__ . '/exceptions/CIPHPUnitTestShow404Exception.php ' ;
102+ require __DIR__ . '/exceptions/CIPHPUnitTestShowErrorException.php ' ;
103+ require __DIR__ . '/exceptions/CIPHPUnitTestExitException.php ' ;
104+ }
105+
106+ protected static function enablePatcher ()
107+ {
108+ require __DIR__ . '/patcher/CIPHPUnitTestIncludeStream.php ' ;
109+ require __DIR__ . '/patcher/CIPHPUnitTestPatchPathChecker.php ' ;
110+ require __DIR__ . '/patcher/CIPHPUnitTestPatcher.php ' ;
111+
112+ // Register include stream wrapper for monkey patching
113+ CIPHPUnitTestIncludeStream::wrap ();
114+
115+ CIPHPUnitTestPatchPathChecker::setWhitelistDir (
116+ [
117+ APPPATH ,
118+ ]
119+ );
120+ CIPHPUnitTestPatchPathChecker::setBlacklistDir (
121+ [
122+ realpath (APPPATH . '../vendor/ ' ),
123+ APPPATH . 'tests/ ' ,
124+ ]
125+ );
126+
127+ self ::setPatcherCacheDir ();
128+ }
129+
130+ public static function setPatcherCacheDir ()
131+ {
132+ CIPHPUnitTestPatcher::setCacheDir (
133+ APPPATH . 'tests/_ci_phpunit_test/tmp/cache '
134+ );
80135 }
81136
82137 public static function loadLoader ()
0 commit comments