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
|
|
|
class CIPHPUnitTestUnitTestCase extends CIPHPUnitTestCase |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Create a controller instance |
15
|
|
|
* |
16
|
|
|
* @param string $classname |
17
|
|
|
* @return CI_Controller |
18
|
|
|
*/ |
19
|
|
|
public function newController($classname) |
20
|
|
|
{ |
21
|
|
|
reset_instance(); |
22
|
|
|
$controller = new $classname; |
23
|
|
|
$this->CI =& get_instance(); |
24
|
|
|
return $controller; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a model instance |
29
|
|
|
* |
30
|
|
|
* @param string $classname |
31
|
|
|
* @return CI_Model |
32
|
|
|
*/ |
33
|
|
|
public function newModel($classname) |
34
|
|
|
{ |
35
|
|
|
$this->resetInstance(); |
36
|
|
|
$this->CI->load->model($classname); |
37
|
|
|
|
38
|
|
|
// Is the model in a sub-folder? |
39
|
|
View Code Duplication |
if (($last_slash = strrpos($classname, '/')) !== FALSE) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$classname = substr($classname, ++$last_slash); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->CI->$classname; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create a library instance |
49
|
|
|
* |
50
|
|
|
* @param string $classname |
51
|
|
|
* @param array $args |
52
|
|
|
* @return object |
53
|
|
|
*/ |
54
|
|
|
public function newLibrary($classname, $args = null) |
55
|
|
|
{ |
56
|
|
|
$this->resetInstance(); |
57
|
|
|
$this->CI->load->library($classname, $args); |
58
|
|
|
|
59
|
|
|
// Is the library in a sub-folder? |
60
|
|
View Code Duplication |
if (($last_slash = strrpos($classname, '/')) !== FALSE) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$classname = substr($classname, ++$last_slash); |
63
|
|
|
} |
64
|
|
|
$classname = strtolower($classname); |
65
|
|
|
|
66
|
|
|
return $this->CI->$classname; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.