summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorPascal Kriete <pascal.kriete@ellislab.com>2011-04-21 06:59:45 +0200
committerPascal Kriete <pascal.kriete@ellislab.com>2011-04-21 06:59:45 +0200
commitfe372e30a8f05ec4a77dc9a5ea2ec471b3488bd3 (patch)
treec7997a722ebadaa77faa7c9615edd4aeff2308e9 /tests/lib
parentc5d93cb3d4d8909507cbed548620e58d26c7c4bd (diff)
Fixing up the scope soup, and adding a way to set core config items.
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/ci_testcase.php74
-rw-r--r--tests/lib/common.php18
2 files changed, 78 insertions, 14 deletions
diff --git a/tests/lib/ci_testcase.php b/tests/lib/ci_testcase.php
index a8a272db2..04216e2a8 100644
--- a/tests/lib/ci_testcase.php
+++ b/tests/lib/ci_testcase.php
@@ -4,10 +4,8 @@
// Need a way to change dependencies (core libs and laoded libs)
// Need a way to set the CI class
-class CodeIgniterTestCase extends PHPUnit_Framework_TestCase {
+class CI_TestCase extends PHPUnit_Framework_TestCase {
- public $ci_instance;
- public static $test_instance;
public static $global_map = array(
'benchmark' => 'bm',
'config' => 'cfg',
@@ -23,23 +21,62 @@ class CodeIgniterTestCase extends PHPUnit_Framework_TestCase {
'loader' => 'load'
);
- function __construct()
+ protected $ci_config = array();
+
+ protected $ci_instance;
+ protected static $ci_test_instance;
+
+
+ public function __construct()
{
parent::__construct();
}
// --------------------------------------------------------------------
- // Change what get_instance returns
- function ci_instance($obj)
+ /**
+ * Overwrite runBare
+ *
+ * PHPUnit instantiates the test classes before
+ * running them individually. So right before a test
+ * runs we set our instance. Normally this step would
+ * happen in setUp, but someone is bound to forget to
+ * call the parent method and debugging this is no fun.
+ */
+ public function runBare()
{
+ self::$ci_test_instance = $this;
+ parent::runBare();
+ }
+
+ // --------------------------------------------------------------------
+
+ public static function instance()
+ {
+ return self::$ci_test_instance;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_instance($obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance;
+ }
+
$this->ci_instance = $obj;
}
// --------------------------------------------------------------------
- function ci_set_instance_var($name, $obj)
+ function ci_instance_var($name, $obj = FALSE)
{
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance->$name;
+ }
+
$this->ci_instance->$name =& $obj;
}
@@ -101,7 +138,28 @@ class CodeIgniterTestCase extends PHPUnit_Framework_TestCase {
// --------------------------------------------------------------------
- static function ci_config($item)
+ function ci_set_config($key, $val = '')
+ {
+ if (is_array($key))
+ {
+ $this->ci_config = $key;
+ }
+ else
+ {
+ $this->ci_config[$key] = $val;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_config_array()
+ {
+ return $this->ci_config;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_config_item($item)
{
return '';
}
diff --git a/tests/lib/common.php b/tests/lib/common.php
index 482721a9a..994e9bc22 100644
--- a/tests/lib/common.php
+++ b/tests/lib/common.php
@@ -4,18 +4,24 @@
function &get_instance()
{
- $test = CodeIgniterTestCase::$test_instance;
- return $test->ci_instance;
+ $test = CI_TestCase::instance();
+ $instance = $test->ci_instance();
+ return $instance;
}
-// Config Stuff | @todo High priority!
// --------------------------------------------------------------------
-function get_config() { die('implement me'); }
+function &get_config() {
+ $test = CI_TestCase::instance();
+ $config = $test->ci_config_array();
+
+ return $config;
+}
function config_item($item)
{
- return CodeIgniterTestCase::ci_config($item);
+ $test = CI_TestCase::instance();
+ return $test->ci_config_item($item);
}
// --------------------------------------------------------------------
@@ -27,7 +33,7 @@ function load_class($class, $directory = 'libraries', $prefix = 'CI_')
throw new Exception('Not Implemented: Non-core load_class()');
}
- $test = CodeIgniterTestCase::$test_instance;
+ $test = CI_TestCase::instance();
$obj =& $test->ci_core_class($class);