Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored Unit_test in order to remove redundant code.

The Unit_test::run method was adding another dimension to the
Unit_test::$results array. For example:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [test_name] => first_test
                    [test_datatype] => integer
                    [res_datatype] => integer
                    [result] => passed
                    [file] => ########################################
                    [line] => 60
                    [notes] => Im expecting this test to pass!
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [test_name] => second_test
                    [test_datatype] => integer
                    [res_datatype] => boolean
                    [result] => failed
                    [file] => #######################################
                    [line] => 65
                    [notes] => Im expecting this to fail.
                )

        )

)

The above unneeded dimension created a need to loop through an array in the
Unit_test::result method if the method was looping through all results.

Signed-off-by: Daniel Paul Searles <daniel.paul.searles@gmail.com>
  • Loading branch information...
commit d2ae1d1d7fdc4b8a21369a25487c2c42e5a496bf 1 parent dd8d3d3
Daniel Searles squaresurf authored
Showing with 6 additions and 25 deletions.
  1. +6 −25 system/libraries/Unit_test.php
31 system/libraries/Unit_test.php
View
@@ -158,7 +158,7 @@ public function run($test, $expected = TRUE, $test_name = 'undefined', $notes =
$back = $this->_backtrace();
- $report[] = array (
+ $report = array (
'test_name' => $test_name,
'test_datatype' => gettype($test),
'res_datatype' => $extype,
@@ -170,7 +170,7 @@ public function run($test, $expected = TRUE, $test_name = 'undefined', $notes =
$this->results[] = $report;
- return $this->report($this->result($report));
+ return $this->report($this->result(array($report)));
}
// --------------------------------------------------------------------
@@ -284,30 +284,11 @@ public function result($results = array())
continue;
}
- if (is_array($val))
+ if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val))))
{
- foreach ($val as $k => $v)
- {
- if ( ! in_array($k, $this->_test_items_visible))
- {
- continue;
- }
-
- 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))))
- {
- $val = $line;
- }
- $temp[$CI->lang->line('ut_'.$key)] = $val;
+ $val = $line;
}
+ $temp[$CI->lang->line('ut_'.$key)] = $val;
}
$retval[] = $temp;
@@ -415,4 +396,4 @@ function is_false($test)
}
/* End of file Unit_test.php */
-/* Location: ./system/libraries/Unit_test.php */
+/* Location: ./system/libraries/Unit_test.php */
Please sign in to comment.
Something went wrong with that request. Please try again.