|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Part of ci-phpunit-test |
|
4
|
|
|
* |
|
5
|
|
|
* @author Kenji Suzuki <https://github.com/kenjis> |
|
6
|
|
|
* @license MIT License |
|
7
|
|
|
* @copyright 2015 Kenji Suzuki |
|
8
|
|
|
* @link https://github.com/kenjis/ci-phpunit-test |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Inject instance to load_class() function |
|
13
|
|
|
* |
|
14
|
|
|
* @param string $classname |
|
15
|
|
|
* @param object $instance |
|
16
|
|
|
*/ |
|
17
|
|
|
function load_class_instance($classname, $instance) |
|
18
|
|
|
{ |
|
19
|
|
|
load_class($classname, '', NULL, FALSE, $instance); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Reset CodeIgniter instance |
|
24
|
|
|
*/ |
|
25
|
|
|
function reset_instance() |
|
26
|
|
|
{ |
|
27
|
|
|
// Reset loaded classes |
|
28
|
|
|
load_class('', '', NULL, TRUE); |
|
29
|
|
|
is_loaded('', TRUE); |
|
30
|
|
|
|
|
31
|
|
|
// Reset config functions |
|
32
|
|
|
reset_config(); |
|
33
|
|
|
|
|
34
|
|
|
// Close db connection |
|
35
|
|
|
$CI =& get_instance(); |
|
36
|
|
|
if (isset($CI->db)) |
|
37
|
|
|
{ |
|
38
|
|
|
if ( |
|
39
|
|
|
$CI->db->dsn !== 'sqlite::memory:' |
|
40
|
|
|
&& $CI->db->database !== ':memory:' |
|
41
|
|
|
) |
|
42
|
|
|
{ |
|
43
|
|
|
$CI->db->close(); |
|
44
|
|
|
$CI->db = null; |
|
45
|
|
|
} |
|
46
|
|
|
else |
|
47
|
|
|
{ |
|
48
|
|
|
// Don't close if SQLite in-memory database |
|
49
|
|
|
// If we close it, all tables and stored data will be gone |
|
50
|
|
|
load_class_instance('db', $CI->db); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// Load core classes |
|
55
|
|
|
$BM =& load_class('Benchmark', 'core'); |
|
56
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('BM', $BM); |
|
57
|
|
|
$EXT =& load_class('Hooks', 'core'); |
|
58
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('EXT', $EXT); |
|
59
|
|
|
$CFG =& load_class('Config', 'core'); |
|
60
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('CFG', $CFG); |
|
61
|
|
|
$UNI =& load_class('URI', 'core'); |
|
62
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('UNI', $UNI); |
|
63
|
|
|
// $URI =& load_class('Utf8', 'core'); |
|
|
|
|
|
|
64
|
|
|
// CIPHPUnitTestSuperGlobal::set_Global('URI', $URI); |
|
65
|
|
|
$RTR =& load_class('Router', 'core'); |
|
66
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('RTR', $RTR); |
|
67
|
|
|
$OUT =& load_class('Output', 'core'); |
|
68
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('OUT', $OUT); |
|
69
|
|
|
$SEC =& load_class('Security', 'core'); |
|
70
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('SEC', $SEC); |
|
71
|
|
|
$IN =& load_class('Input', 'core'); |
|
72
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('IN', $IN); |
|
73
|
|
|
$LANG =& load_class('Lang', 'core'); |
|
74
|
|
|
CIPHPUnitTestSuperGlobal::set_Global('LANG', $LANG); |
|
75
|
|
|
|
|
76
|
|
|
CIPHPUnitTest::loadLoader(); |
|
77
|
|
|
|
|
78
|
|
|
// Remove CodeIgniter instance |
|
79
|
|
|
$CI = new CIPHPUnitTestNullCodeIgniter(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Set return value of is_cli() function |
|
84
|
|
|
* |
|
85
|
|
|
* @param bool $return |
|
86
|
|
|
*/ |
|
87
|
|
|
function set_is_cli($return) |
|
88
|
|
|
{ |
|
89
|
|
|
is_cli($return); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Reset config functions |
|
94
|
|
|
*/ |
|
95
|
|
|
function reset_config() |
|
96
|
|
|
{ |
|
97
|
|
|
get_config([], TRUE); |
|
98
|
|
|
config_item(NULL, TRUE); |
|
99
|
|
|
} |
|
100
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.