blob: a8a272db27ce87be3759817fcf45b975347b0185 [file] [log] [blame]
Pascal Kriete69c97a72011-04-20 21:44:54 -04001<?php
2
3
4// Need a way to change dependencies (core libs and laoded libs)
5// Need a way to set the CI class
6
7class CodeIgniterTestCase extends PHPUnit_Framework_TestCase {
8
9 public $ci_instance;
10 public static $test_instance;
11 public static $global_map = array(
12 'benchmark' => 'bm',
13 'config' => 'cfg',
14 'hooks' => 'ext',
15 'utf8' => 'uni',
16 'router' => 'rtr',
17 'output' => 'out',
18 'security' => 'sec',
19 'input' => 'in',
20 'lang' => 'lang',
21
22 // @todo the loader is an edge case
23 'loader' => 'load'
24 );
25
26 function __construct()
27 {
28 parent::__construct();
29 }
30
31 // --------------------------------------------------------------------
32
33 // Change what get_instance returns
34 function ci_instance($obj)
35 {
36 $this->ci_instance = $obj;
37 }
38
39 // --------------------------------------------------------------------
40
41 function ci_set_instance_var($name, $obj)
42 {
43 $this->ci_instance->$name =& $obj;
44 }
45
46 // --------------------------------------------------------------------
47
48 // Set a class to a mock before it is loaded
49 function ci_library($name)
50 {
51
52 }
53
54 // --------------------------------------------------------------------
55
56 /**
57 * Grab a core class
58 *
59 * Loads the correct core class without extensions
60 * and returns a reference to the class name in the
61 * globals array with the correct key. This way the
62 * test can modify the variable it assigns to and
63 * still maintain the global.
64 */
65 function &ci_core_class($name)
66 {
67 $name = strtolower($name);
68
69 if (isset(self::$global_map[$name]))
70 {
71 $class_name = ucfirst($name);
72 $global_name = self::$global_map[$name];
73 }
74 elseif (in_array($name, self::$global_map))
75 {
76 $class_name = ucfirst(array_search($name, self::$global_map));
77 $global_name = $name;
78 }
79 else
80 {
81 throw new Exception('Not a valid core class.');
82 }
83
84 if ( ! class_exists('CI_'.$class_name))
85 {
86 require_once BASEPATH.'core/'.$class_name.'.php';
87 }
88
89 $GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name;
90 return $GLOBALS[strtoupper($global_name)];
91 }
92
93 // --------------------------------------------------------------------
94
95 // convenience function for global mocks
96 function ci_set_core_class($name, $obj)
97 {
98 $orig =& $this->ci_core_class($name);
99 $orig = $obj;
100 }
101
102 // --------------------------------------------------------------------
103
104 static function ci_config($item)
105 {
106 return '';
107 }
108}
109
110// EOF