From 0ce73efdef39b5760766fcdde08485e94b754953 Mon Sep 17 00:00:00 2001
From: Derek Allard
Date: Mon, 18 Jan 2010 15:48:25 +0000
Subject: The Unit Test Class now has an optional "notes" field available to
it, and allows for discrete display of test result items using
$this->unit->set_test_items().
---
system/libraries/Unit_test.php | 60 +++++++++++++++++++++++++++-------
user_guide/changelog.html | 3 +-
user_guide/libraries/unit_testing.html | 28 +++++++++++++---
3 files changed, 74 insertions(+), 17 deletions(-)
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index a6427b2c3..c47143637 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -28,19 +28,50 @@
*/
class CI_Unit_test {
- var $active = TRUE;
- var $results = array();
- var $strict = FALSE;
- var $_template = NULL;
- var $_template_rows = NULL;
+ var $active = TRUE;
+ var $results = array();
+ var $strict = FALSE;
+ var $_template = NULL;
+ var $_template_rows = NULL;
+ var $_test_items_visible = array();
function CI_Unit_test()
{
+ // These are the default items visible when a test is run.
+ $this->_test_items_visible = array (
+ 'test_name',
+ 'test_datatype',
+ 'res_datatype',
+ 'result',
+ 'file',
+ 'line',
+ 'notes'
+ );
+
log_message('debug', "Unit Testing Class Initialized");
- }
+ }
// --------------------------------------------------------------------
-
+
+ /**
+ * Run the tests
+ *
+ * Runs the supplied tests
+ *
+ * @access public
+ * @param array
+ * @return void
+ */
+ function set_test_items($items = array())
+ {
+ if ( ! empty($items) AND is_array($items))
+ {
+ $this->_test_items_visible = $items;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Run the tests
*
@@ -52,7 +83,7 @@ class CI_Unit_test {
* @param string
* @return string
*/
- function run($test, $expected = TRUE, $test_name = 'undefined')
+ function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
{
if ($this->active == FALSE)
{
@@ -83,11 +114,12 @@ class CI_Unit_test {
'res_datatype' => $extype,
'result' => ($result === TRUE) ? 'passed' : 'failed',
'file' => $back['file'],
- 'line' => $back['line']
+ 'line' => $back['line'],
+ 'notes' => $notes
);
- $this->results[] = $report;
-
+ $this->results[] = $report;
+
return($this->report($this->result($report)));
}
@@ -120,7 +152,6 @@ class CI_Unit_test {
foreach ($res as $key => $val)
{
-
if ($key == $CI->lang->line('ut_result'))
{
if ($val == $CI->lang->line('ut_passed'))
@@ -203,6 +234,11 @@ class CI_Unit_test {
$temp = array();
foreach ($result as $key => $val)
{
+ if ( ! in_array($key, $this->_test_items_visible))
+ {
+ continue;
+ }
+
if (is_array($val))
{
foreach ($val as $k => $v)
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 6dbdc1bed..b8601ab3a 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -69,6 +69,7 @@ SVN Revision:
Added a parse_string() method to the Parser Class.
Added HTTP headers and Config information to the Profiler output.
Added Chrome and Flock to the list of detectable browsers by browser() in the User Agent Class.
+ The Unit Test Class now has an optional "notes" field available to it, and allows for discrete display of test result items using $this->unit->set_test_items().
Database
@@ -114,7 +115,7 @@ SVN Revision:
Fixed a bug in reduce_double_slashes() in the String Helper to properly remove duplicate leading slashes (#7585)
Fixed a bug in values_parsing() of the XML-RPC library which prevented NULL variables typed as 'string' from being handled properly.
Fixed a bug were form_open_multipart() didn't accept string attribute arguments (#10930).
- Fixed a bug (#10470) where get_mime_by_extension() case sensitive.
+ Fixed a bug (#10470) where get_mime_by_extension() was case sensitive.
Version 1.7.2
diff --git a/user_guide/libraries/unit_testing.html b/user_guide/libraries/unit_testing.html
index b9916045e..bf86738f4 100644
--- a/user_guide/libraries/unit_testing.html
+++ b/user_guide/libraries/unit_testing.html
@@ -79,10 +79,10 @@ to determine if it is producing the correct data type and result.
Running a test involves supplying a test and an expected result to the following function:
-$this->unit->run( test, expected result, 'test name' );
+$this->unit->run( test, expected result, 'test name', 'notes');
-Where test is the result of the code you wish to test,
-expected result is the data type you expect, and test name is an optional name you can give your test. Example:
+Where test is the result of the code you wish to test, expected result is the data type you expect,
+test name is an optional name you can give your test, and notes are optional notes. Example:
$test = 1 + 1;
@@ -160,9 +160,29 @@ unit testing using:
$this->unit->active(FALSE)
+Unit Test Display
+When your unit test results display, the following items show by default:
-Creating a Template
+
+ - Test Name (test_name)
+ - Test Datatype (test_datatype)
+ - Expected Datatype (res_datatype)
+ - Result (result)
+ - File Name (file)
+ - Line Number (line)
+ - Any notes you entered for the test (notes)
+
+
+You can customize which of these items get displayed by using $this->unit->set_items(). For example, if you only wanted the test name and the result displayed:
+
+Customizing displayed tests
+
+
+ $this->unit->set_test_items(array('test_name', 'result'));
+
+
+Creating a Template
If you would like your test results formatted differently then the default you can set your own template. Here is an
example of a simple template. Note the required pseudo-variables:
--
cgit v1.2.3-24-g4f1b