Patch of pached CIUnit(https://bitbucket.org/kenjis/my-ciunit).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ur ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/config/config.php src/application/third_party/CIUnit/config/config.php | |
--- ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/config/config.php 2012-01-18 01:27:00.000000000 +0900 | |
+++ src/application/third_party/CIUnit/config/config.php 2013-04-03 17:56:13.738279800 +0900 | |
@@ -8,6 +8,8 @@ | |
*/ | |
$config['ciu_subclass_prefix'] = 'CIU_'; | |
+$config['log_threshold'] = 4; | |
+$config['log_path'] = 'logs/'; | |
/* End of file config.php */ | |
/* Location ./application/third_party/CIUnit/config/config.php */ | |
diff -ur ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/core/CIU_Loader.php src/application/third_party/CIUnit/core/CIU_Loader.php | |
--- ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/core/CIU_Loader.php 2012-01-18 01:27:00.000000000 +0900 | |
+++ src/application/third_party/CIUnit/core/CIU_Loader.php 2013-03-21 09:42:32.017522800 +0900 | |
@@ -431,6 +431,15 @@ | |
$this->_ci_models = array(); | |
$this->_ci_helpers = array(); | |
} | |
+ | |
+ public function library($library = '', $params = NULL, $object_name = NULL) | |
+ { | |
+ $CI =& get_instance(); | |
+ if (isset($CI->$library)) { | |
+ unset($CI->$library); | |
+ } | |
+ return parent::library($library, $params, $library); //force reload | |
+ } | |
} | |
/* End of file CIU_Loader.php */ | |
diff -ur ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/core/CIU_Output.php src/application/third_party/CIUnit/core/CIU_Output.php | |
--- ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/core/CIU_Output.php 2012-01-18 01:27:00.000000000 +0900 | |
+++ src/application/third_party/CIUnit/core/CIU_Output.php 2013-03-19 15:39:08.587308900 +0900 | |
@@ -97,6 +97,14 @@ | |
{ | |
return $this->headers; | |
} | |
+ | |
+ /** | |
+ * reset headers | |
+ */ | |
+ function reset_headers() | |
+ { | |
+ $this->headers = array(); | |
+ } | |
/** | |
* say | |
diff -ur ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/libraries/CIUnitTestCase.php src/application/third_party/CIUnit/libraries/CIUnitTestCase.php | |
--- ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/libraries/CIUnitTestCase.php 2012-01-18 01:27:00.000000000 +0900 | |
+++ src/application/third_party/CIUnit/libraries/CIUnitTestCase.php 2013-04-02 20:53:02.647772600 +0900 | |
@@ -82,6 +82,10 @@ | |
{ | |
$this->dbfixt($this->tables); | |
} | |
+ | |
+ // Clear POST and GET | |
+ $_POST = array(); | |
+ $_GET = array(); | |
} | |
/** | |
@@ -132,12 +136,23 @@ | |
*/ | |
foreach($table_fixtures as $table => $fixt ) | |
{ | |
+ if (is_array($fixt)) { | |
+ $dbgroup = $fixt[0]; | |
+ $fixt = $fixt[1]; | |
+ } else { | |
+ $dbgroup = null; | |
+ } | |
+ | |
$fixt_name = $fixt . '_fixt'; | |
$table = is_int($table) ? $fixt : $table; | |
if (!empty($this->$fixt_name)) | |
{ | |
- CIUnit::$fixture->load($table, $this->$fixt_name); | |
+ if ($dbgroup) { | |
+ CIUnit::$fixture->load($table, $this->$fixt_name, $dbgroup); | |
+ } else { | |
+ CIUnit::$fixture->load($table, $this->$fixt_name); | |
+ } | |
} | |
else | |
{ | |
@@ -146,7 +161,19 @@ | |
} | |
- log_message('debug', 'Table fixtures "' . join('", "', $table_fixtures) . '" loaded'); | |
+ log_message('debug', 'Table fixtures "' . join('", "', $this->array_flatten($table_fixtures)) . '" loaded'); | |
+ } | |
+ | |
+ function array_flatten($nested) { | |
+ $flat = array(); | |
+ foreach($nested as $key => $x) { | |
+ if (is_array($x)) { | |
+ $flat[$key] = join('" : "', $x); | |
+ } else { | |
+ $flat[$key] = $x; | |
+ } | |
+ } | |
+ return $flat; | |
} | |
/** | |
@@ -184,7 +211,13 @@ | |
// Iterate over the array unloading the tables | |
foreach ($table_fixtures as $table => $fixture) | |
{ | |
- CIUnit::$fixture->unload($table); | |
+ if (is_array($fixture)) { | |
+ $dbgroup = $fixture[0]; | |
+ $fixture = $fixture[1]; | |
+ CIUnit::$fixture->unload($table, $dbgroup); | |
+ } else { | |
+ CIUnit::$fixture->unload($table); | |
+ } | |
log_message('debug', 'Table fixture "' . $fixture . '" unloaded'); | |
} | |
} | |
@@ -205,6 +238,10 @@ | |
{ | |
foreach ( $fixts as $fixt ) | |
{ | |
+ if (is_array($fixt)) { | |
+ $fixt = $fixt[1]; | |
+ } | |
+ | |
$fixt_name = $fixt . '_fixt'; | |
if (file_exists(TESTSPATH . 'fixtures/' . $fixt . '_fixt.yml')) { | |
diff -ur ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/libraries/Fixture.php src/application/third_party/CIUnit/libraries/Fixture.php | |
--- ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/libraries/Fixture.php 2012-01-18 01:27:00.000000000 +0900 | |
+++ src/application/third_party/CIUnit/libraries/Fixture.php 2013-04-02 15:27:03.503092100 +0900 | |
@@ -25,13 +25,13 @@ | |
/** | |
* loads fixture data $fixt into corresponding table | |
*/ | |
- function load($table, $fixt) | |
+ function load($table, $fixt, $dbgroup = 'default') | |
{ | |
- $this->_assign_db(); | |
+ $this->_assign_db($dbgroup); | |
// $fixt is supposed to be an associative array | |
// E.g. outputted by spyc from reading a YAML file | |
- $this->CI->db->simple_query('truncate table ' . $table . ';'); | |
+ $this->db->simple_query('truncate table ' . $table . ';'); | |
foreach ( $fixt as $id => $row ) | |
{ | |
@@ -39,13 +39,17 @@ | |
{ | |
if ($val !== '') | |
{ | |
- $row["`$key`"] = $val; | |
+ if ($this->db->dbdriver == "postgre") | |
+ { | |
+ $row["\"$key\""] = $val; | |
+ } else { | |
+ $row["`$key`"] = $val; | |
+ } | |
} | |
//unset the rest | |
- unset($row[$key]); | |
} | |
- $this->CI->db->insert($table, $row); | |
+ $this->db->insert($table, $row); | |
} | |
$nbr_of_rows = sizeof($fixt); | |
@@ -53,33 +57,29 @@ | |
"Data fixture for db table '$table' loaded - $nbr_of_rows rows"); | |
} | |
- public function unload($table) | |
+ public function unload($table, $dbgroup = 'default') | |
{ | |
- $this->_assign_db(); | |
+ $this->_assign_db($dbgroup); | |
- $Q = $this->CI->db->simple_query('truncate table ' . $table . ';'); | |
+ $Q = $this->db->simple_query('truncate table ' . $table . ';'); | |
if (!$Q) { | |
- echo $this->CI->db->call_function('error', $this->CI->db->conn_id); | |
+ echo $this->db->call_function('error', $this->db->conn_id); | |
echo "\n"; | |
echo "Failed to truncate the table ".$table."\n\n"; | |
} | |
} | |
- private function _assign_db() | |
+ private function _assign_db($dbgroup) | |
{ | |
- if ( ! isset($this->CI->db) OR | |
- ! isset($this->CI->db->database) ) | |
- { | |
- $this->CI =& get_instance(); | |
- $this->CI->load->database(); | |
- } | |
+ $this->CI =& get_instance(); | |
+ $this->db = $this->CI->load->database($dbgroup, true); | |
//security measure 2: only load if used database ends on '_test' | |
- $len = strlen($this->CI->db->database); | |
+ $len = strlen($this->db->database); | |
- if ( substr($this->CI->db->database, $len-5, $len) != '_test' ) | |
+ if ( substr($this->db->database, $len-5, $len) != '_test' ) | |
{ | |
die("\nSorry, the name of your test database must end on '_test'.\n". | |
"This prevents deleting important data by accident.\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Features:
Multi database idiom:
Plain setting are using 'default' database.
Array setting are using $db['subdb'] of config/testing/database.php.