From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 0f6e2dfdd..6ec2dcd5d 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -350,11 +350,11 @@ class CI_Unit_test { */ function is_true($test) { - return (is_bool($test) && $test === TRUE); + return ($test === TRUE); } function is_false($test) { - return (is_bool($test) && $test === FALSE); + return ($test === FALSE); } /* End of file Unit_test.php */ -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Unit_test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 6ec2dcd5d..a87cf7e14 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -93,7 +93,7 @@ class CI_Unit_test { */ public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') { - if ($this->active == FALSE) + if ($this->active === FALSE) { return FALSE; } @@ -106,7 +106,7 @@ class CI_Unit_test { } else { - $result = ($this->strict == TRUE) ? ($test === $expected) : ($test == $expected); + $result = ($this->strict === TRUE) ? ($test === $expected) : ($test === $expected); $extype = gettype($expected); } @@ -155,13 +155,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 = ''.$val.''; } - elseif ($val == $CI->lang->line('ut_failed')) + elseif ($val === $CI->lang->line('ut_failed')) { $val = ''.$val.''; } -- cgit v1.2.3-24-g4f1b From c839d28f4230dce0c658338f267b821cc16490a2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 7 Jun 2012 14:35:27 +0300 Subject: Remove some unnecessary function_exists() checks and some minor improvements --- system/libraries/Unit_test.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index a87cf7e14..70ad8dc41 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -124,7 +124,7 @@ class CI_Unit_test { $this->results[] = $report; - return($this->report($this->result($report))); + return $this->report($this->result($report)); } // -------------------------------------------------------------------- @@ -289,15 +289,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'] : '') + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c4a3c3cb01dcc5fbcd079313a8576c701f3f54ff Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 3 Oct 2012 14:34:37 -0700 Subject: Updated result function to check for visible items as defined in issue #395 --- system/libraries/Unit_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 70ad8dc41..435c32693 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -240,6 +240,11 @@ class CI_Unit_test { { 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; -- cgit v1.2.3-24-g4f1b From 9438e26671ee1f0b49c8da7a56a0a195788fd5da Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 13:16:27 +0300 Subject: Fix issue #116 + other space/style fixes [ci skip --- system/libraries/Unit_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 435c32693..c2c01758e 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -244,7 +244,7 @@ class CI_Unit_test { { continue; } - + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) { $v = $line; -- cgit v1.2.3-24-g4f1b From 5fd3ae8d33a4f5d3159b86683b9a670e973a63f5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 14:55:35 +0300 Subject: [ci skip] style and phpdoc-related changes (rel #1295) --- system/libraries/Unit_test.php | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index c2c01758e..7b99dee0d 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -38,13 +38,18 @@ */ class CI_Unit_test { - public $active = TRUE; - public $results = array(); - public $strict = FALSE; - protected $_template = NULL; - protected $_template_rows = NULL; + public $active = TRUE; + public $results = array(); + public $strict = FALSE; + protected $_template = NULL; + protected $_template_rows = NULL; protected $_test_items_visible = array(); + /** + * Constructor + * + * @return void + */ public function __construct() { // These are the default items visible when a test is run. @@ -86,9 +91,10 @@ class CI_Unit_test { * * Runs the supplied tests * - * @param mixed - * @param mixed - * @param string + * @param mixed $test + * @param mixed $expected = TRUE + * @param string $test_name = 'undefined' + * @param string $notes = '' * @return string */ public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') @@ -134,6 +140,7 @@ class CI_Unit_test { * * Displays a table with the test data * + * @param array $result = array() * @return string */ public function report($result = array()) @@ -213,6 +220,7 @@ class CI_Unit_test { * * Returns the raw result data * + * @param array $results = array() * @return array */ public function result($results = array()) @@ -345,14 +353,22 @@ 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 ($test === TRUE); } + +/** + * Helper function to test boolean FALSE + * + * @param mixed $test + * @return bool + */ function is_false($test) { return ($test === FALSE); -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Unit_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 7b99dee0d..5c0018d35 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,4 +1,4 @@ - Date: Thu, 1 Nov 2012 22:56:26 +0200 Subject: [ci skip] DocBlocks for Email, Ftp, Unit_test and Javascript libraries Partially fixes issue #1295 --- system/libraries/Unit_test.php | 51 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 5c0018d35..2710b5513 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -39,13 +39,52 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_Unit_test { + /** + * 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 * @@ -93,9 +132,9 @@ class CI_Unit_test { * Runs the supplied tests * * @param mixed $test - * @param mixed $expected = TRUE - * @param string $test_name = 'undefined' - * @param string $notes = '' + * @param mixed $expected + * @param string $test_name + * @param string $notes * @return string */ public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') @@ -113,7 +152,7 @@ class CI_Unit_test { } else { - $result = ($this->strict === TRUE) ? ($test === $expected) : ($test === $expected); + $result = ($this->strict === TRUE) ? ($test === $expected) : ($test == $expected); $extype = gettype($expected); } @@ -141,7 +180,7 @@ class CI_Unit_test { * * Displays a table with the test data * - * @param array $result = array() + * @param array $result * @return string */ public function report($result = array()) @@ -221,7 +260,7 @@ class CI_Unit_test { * * Returns the raw result data * - * @param array $results = array() + * @param array $results * @return array */ public function result($results = array()) -- cgit v1.2.3-24-g4f1b From d2ae1d1d7fdc4b8a21369a25487c2c42e5a496bf Mon Sep 17 00:00:00 2001 From: Daniel Paul Searles Date: Fri, 2 Nov 2012 17:39:44 -0700 Subject: 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 --- system/libraries/Unit_test.php | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 2710b5513..842b4aebd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -158,7 +158,7 @@ class CI_Unit_test { $back = $this->_backtrace(); - $report[] = array ( + $report = array ( 'test_name' => $test_name, 'test_datatype' => gettype($test), 'res_datatype' => $extype, @@ -170,7 +170,7 @@ class CI_Unit_test { $this->results[] = $report; - return $this->report($this->result($report)); + return $this->report($this->result(array($report))); } // -------------------------------------------------------------------- @@ -284,30 +284,11 @@ class CI_Unit_test { 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 */ \ No newline at end of file +/* Location: ./system/libraries/Unit_test.php */ -- cgit v1.2.3-24-g4f1b From ce0c9561e9068d5dab9c473f1ca0709b0d222cf1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Nov 2012 17:26:29 +0200 Subject: Fix issue #118 (manually implementing PR #1832) --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Unit_test.php') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 842b4aebd..05c7eef78 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -284,11 +284,11 @@ class CI_Unit_test { continue; } - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val), FALSE))) { $val = $line; } - $temp[$CI->lang->line('ut_'.$key)] = $val; + $temp[$CI->lang->line('ut_'.$key, FALSE)] = $val; } $retval[] = $temp; -- cgit v1.2.3-24-g4f1b