summaryrefslogtreecommitdiffstats
path: root/system/libraries/Unit_test.php
diff options
context:
space:
mode:
authorEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
committerEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
commitb9e35f21e1c70b6aa67c47e9244ed83195abc00a (patch)
tree64f82db362deeac48cc20d1d1afd80651f36f5a5 /system/libraries/Unit_test.php
parent0b05705c52c3bca7f9b3aee657c888e8ad1ff422 (diff)
parent545a7c86701875e1412bcde316e9bcc76d9a23a0 (diff)
Merge branch 'refs/heads/develop' into feature/form_error_msgs
Conflicts: system/language/english/form_validation_lang.php user_guide_src/source/libraries/form_validation.rst Signed-off-by: Eric Roberts <eric@cryode.com>
Diffstat (limited to 'system/libraries/Unit_test.php')
-rw-r--r--system/libraries/Unit_test.php130
1 files changed, 84 insertions, 46 deletions
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index 0f6e2dfdd..05c7eef78 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.3.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Unit Testing Class
@@ -38,13 +39,57 @@
*/
class CI_Unit_test {
- public $active = TRUE;
- public $results = array();
- public $strict = FALSE;
- protected $_template = NULL;
- protected $_template_rows = NULL;
+ /**
+ * Active flag
+ *
+ * @var bool
+ */
+ public $active = TRUE;
+
+ /**
+ * Test results
+ *
+ * @var array
+ */
+ public $results = array();
+
+ /**
+ * Strict comparison flag
+ *
+ * Whether to use === or == when comparing
+ *
+ * @var bool
+ */
+ public $strict = FALSE;
+
+ /**
+ * Template
+ *
+ * @var string
+ */
+ protected $_template = NULL;
+
+ /**
+ * Template rows
+ *
+ * @var string
+ */
+ protected $_template_rows = NULL;
+
+ /**
+ * List of visible test items
+ *
+ * @var array
+ */
protected $_test_items_visible = array();
+ // --------------------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @return void
+ */
public function __construct()
{
// These are the default items visible when a test is run.
@@ -86,14 +131,15 @@ class CI_Unit_test {
*
* Runs the supplied tests
*
- * @param mixed
- * @param mixed
- * @param string
+ * @param mixed $test
+ * @param mixed $expected
+ * @param string $test_name
+ * @param string $notes
* @return string
*/
public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
{
- if ($this->active == FALSE)
+ if ($this->active === FALSE)
{
return FALSE;
}
@@ -106,13 +152,13 @@ class CI_Unit_test {
}
else
{
- $result = ($this->strict == TRUE) ? ($test === $expected) : ($test == $expected);
+ $result = ($this->strict === TRUE) ? ($test === $expected) : ($test == $expected);
$extype = gettype($expected);
}
$back = $this->_backtrace();
- $report[] = array (
+ $report = array (
'test_name' => $test_name,
'test_datatype' => gettype($test),
'res_datatype' => $extype,
@@ -124,7 +170,7 @@ class CI_Unit_test {
$this->results[] = $report;
- return($this->report($this->result($report)));
+ return $this->report($this->result(array($report)));
}
// --------------------------------------------------------------------
@@ -134,6 +180,7 @@ class CI_Unit_test {
*
* Displays a table with the test data
*
+ * @param array $result
* @return string
*/
public function report($result = array())
@@ -155,13 +202,13 @@ class CI_Unit_test {
foreach ($res as $key => $val)
{
- if ($key == $CI->lang->line('ut_result'))
+ if ($key === $CI->lang->line('ut_result'))
{
- if ($val == $CI->lang->line('ut_passed'))
+ if ($val === $CI->lang->line('ut_passed'))
{
$val = '<span style="color: #0C0;">'.$val.'</span>';
}
- elseif ($val == $CI->lang->line('ut_failed'))
+ elseif ($val === $CI->lang->line('ut_failed'))
{
$val = '<span style="color: #C00;">'.$val.'</span>';
}
@@ -213,6 +260,7 @@ class CI_Unit_test {
*
* Returns the raw result data
*
+ * @param array $results
* @return array
*/
public function result($results = array())
@@ -236,25 +284,11 @@ class CI_Unit_test {
continue;
}
- if (is_array($val))
- {
- foreach ($val as $k => $v)
- {
- if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v))))
- {
- $v = $line;
- }
- $temp[$CI->lang->line('ut_'.$k)] = $v;
- }
- }
- else
+ if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val), FALSE)))
{
- if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val))))
- {
- $val = $line;
- }
- $temp[$CI->lang->line('ut_'.$key)] = $val;
+ $val = $line;
}
+ $temp[$CI->lang->line('ut_'.$key, FALSE)] = $val;
}
$retval[] = $temp;
@@ -289,15 +323,11 @@ class CI_Unit_test {
*/
protected function _backtrace()
{
- if (function_exists('debug_backtrace'))
- {
- $back = debug_backtrace();
- return array(
- 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''),
- 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '')
- );
- }
- return array('file' => 'Unknown', 'line' => 'Unknown');
+ $back = debug_backtrace();
+ return array(
+ 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''),
+ 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '')
+ );
}
// --------------------------------------------------------------------
@@ -344,18 +374,26 @@ class CI_Unit_test {
}
/**
- * Helper functions to test boolean true/false
+ * Helper function to test boolean TRUE
*
+ * @param mixed $test
* @return bool
*/
function is_true($test)
{
- return (is_bool($test) && $test === TRUE);
+ return ($test === TRUE);
}
+
+/**
+ * Helper function to test boolean FALSE
+ *
+ * @param mixed $test
+ * @return bool
+ */
function is_false($test)
{
- return (is_bool($test) && $test === FALSE);
+ return ($test === FALSE);
}
/* End of file Unit_test.php */
-/* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file
+/* Location: ./system/libraries/Unit_test.php */