Completed
Push — master ( bb2773...2c6391 )
by Kenji
27s queued 11s
created

functions.php ➔ is_testing_env()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
60
	$CFG =& load_class('Config', 'core');
61
	CIPHPUnitTestSuperGlobal::set_Global('CFG', $CFG);
62
	// Do we have any manually set config items in the index.php file?
63
	global $assign_to_config;
64
	if (isset($assign_to_config) && is_array($assign_to_config))
65
	{
66
		foreach ($assign_to_config as $key => $value)
67
		{
68
			$CFG->set_item($key, $value);
69
		}
70
	}
71
72
	$UNI =& load_class('URI', 'core');
73
	CIPHPUnitTestSuperGlobal::set_Global('UNI', $UNI);
74
//	$URI =& load_class('Utf8', 'core');
75
//	CIPHPUnitTestSuperGlobal::set_Global('URI', $URI);
76
	$RTR =& load_class('Router', 'core');
77
	CIPHPUnitTestSuperGlobal::set_Global('RTR', $RTR);
78
	$OUT =& load_class('Output', 'core');
79
	CIPHPUnitTestSuperGlobal::set_Global('OUT', $OUT);
80
	$SEC =& load_class('Security', 'core');
81
	CIPHPUnitTestSuperGlobal::set_Global('SEC', $SEC);
82
	$IN =& load_class('Input', 'core');
83
	CIPHPUnitTestSuperGlobal::set_Global('IN', $IN);
84
	$LANG =& load_class('Lang', 'core');
85
	CIPHPUnitTestSuperGlobal::set_Global('LANG', $LANG);
86
87
	CIPHPUnitTest::loadLoader();
88
	if (CIPHPUnitTest::wiredesignzHmvcInstalled()) {
89
		CIPHPUnitTest::loadConfig();
90
	}
91
92
	// Remove CodeIgniter instance
93
	$CI = new CIPHPUnitTestNullCodeIgniter();
94
95
	// Reset Logs
96
	CIPHPUnitTestLogger::resetLogs();
97
}
98
99
/**
100
 * Set return value of is_cli() function
101
 *
102
 * @param bool $return
103
 */
104
function set_is_cli($return)
105
{
106
	is_cli($return);
0 ignored issues
show
Unused Code introduced by
The call to the function is_cli() seems unnecessary as the function has no side-effects.
Loading history...
107
}
108
109
/**
110
 * Reset config functions
111
 */
112
function reset_config()
113
{
114
	get_config([], TRUE);
115
	config_item(NULL, TRUE);
116
}
117
118
if ( ! function_exists('is_testing_env'))
119
{
120
	/**
121
	 * Testing Environment or not?
122
	 *
123
	 * @return bool
124
	 */
125
	function is_testing_env()
126
	{
127
		return (ENVIRONMENT === 'testing');
128
	}
129
}
130