summaryrefslogtreecommitdiffstats
path: root/system/libraries/Unit_test.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-01-03 10:01:50 +0100
committerAndrey Andreev <narf@bofh.bg>2012-01-03 10:01:50 +0100
commit166396ed9e03f78444970372983d50fd34a5ca96 (patch)
treef209bdbc89c0e4310ebf772299e0bd7e7ecef68d /system/libraries/Unit_test.php
parentb195637240bbbc7c3dc7ee0585f0e4cd39cb9d81 (diff)
parent29e1122c19c532b7299598fb7ddfb7f15264ad78 (diff)
Merge remote-tracking branch 'upstream/develop' into develop-xmlrpc
Diffstat (limited to 'system/libraries/Unit_test.php')
-rw-r--r--system/libraries/Unit_test.php104
1 files changed, 37 insertions, 67 deletions
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index 7afe40b09..38d767c69 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.3.1
@@ -40,12 +40,12 @@
*/
class CI_Unit_test {
- var $active = TRUE;
- var $results = array();
- var $strict = FALSE;
- var $_template = NULL;
- var $_template_rows = NULL;
- var $_test_items_visible = array();
+ public $active = TRUE;
+ public $results = array();
+ public $strict = FALSE;
+ protected $_template = NULL;
+ protected $_template_rows = NULL;
+ protected $_test_items_visible = array();
public function __construct()
{
@@ -70,11 +70,10 @@ class CI_Unit_test {
*
* Runs the supplied tests
*
- * @access public
* @param array
* @return void
*/
- function set_test_items($items = array())
+ public function set_test_items($items = array())
{
if ( ! empty($items) AND is_array($items))
{
@@ -89,13 +88,12 @@ class CI_Unit_test {
*
* Runs the supplied tests
*
- * @access public
* @param mixed
* @param mixed
* @param string
* @return string
*/
- function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
+ public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
{
if ($this->active == FALSE)
{
@@ -110,11 +108,7 @@ class CI_Unit_test {
}
else
{
- if ($this->strict == TRUE)
- $result = ($test === $expected) ? TRUE : FALSE;
- else
- $result = ($test == $expected) ? TRUE : FALSE;
-
+ $result = ($this->strict == TRUE) ? ($test === $expected) : ($test == $expected);
$extype = gettype($expected);
}
@@ -142,12 +136,11 @@ class CI_Unit_test {
*
* Displays a table with the test data
*
- * @access public
* @return string
*/
- function report($result = array())
+ public function report($result = array())
{
- if (count($result) == 0)
+ if (count($result) === 0)
{
$result = $this->result();
}
@@ -176,10 +169,7 @@ class CI_Unit_test {
}
}
- $temp = $this->_template_rows;
- $temp = str_replace('{item}', $key, $temp);
- $temp = str_replace('{result}', $val, $temp);
- $table .= $temp;
+ $table .= str_replace(array('{item}', '{result}'), array($key, $val), $this->_template_rows);
}
$r .= str_replace('{rows}', $table, $this->_template);
@@ -195,13 +185,12 @@ class CI_Unit_test {
*
* Causes the evaluation to use === rather than ==
*
- * @access public
* @param bool
* @return null
*/
- function use_strict($state = TRUE)
+ public function use_strict($state = TRUE)
{
- $this->strict = ($state == FALSE) ? FALSE : TRUE;
+ $this->strict = (bool) $state;
}
// --------------------------------------------------------------------
@@ -211,13 +200,12 @@ class CI_Unit_test {
*
* Enables/disables unit testing
*
- * @access public
* @param bool
* @return null
*/
- function active($state = TRUE)
+ public function active($state = TRUE)
{
- $this->active = ($state == FALSE) ? FALSE : TRUE;
+ $this->active = (bool) $state;
}
// --------------------------------------------------------------------
@@ -227,15 +215,14 @@ class CI_Unit_test {
*
* Returns the raw result data
*
- * @access public
* @return array
*/
- function result($results = array())
+ public function result($results = array())
{
$CI =& get_instance();
$CI->load->language('unit_test');
- if (count($results) == 0)
+ if (count($results) === 0)
{
$results = $this->results;
}
@@ -285,11 +272,10 @@ class CI_Unit_test {
*
* This lets us set the template to be used to display results
*
- * @access public
* @param string
* @return void
*/
- function set_template($template)
+ public function set_template($template)
{
$this->_template = $template;
}
@@ -301,19 +287,17 @@ class CI_Unit_test {
*
* This lets us show file names and line numbers
*
- * @access private
* @return array
*/
- function _backtrace()
+ protected function _backtrace()
{
if (function_exists('debug_backtrace'))
{
$back = debug_backtrace();
-
- $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file'];
- $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line'];
-
- return array('file' => $file, 'line' => $line);
+ return array(
+ 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''),
+ 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '')
+ );
}
return array('file' => 'Unknown', 'line' => 'Unknown');
}
@@ -323,19 +307,14 @@ class CI_Unit_test {
/**
* Get Default Template
*
- * @access private
* @return string
*/
- function _default_template()
+ protected function _default_template()
{
- $this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">';
- $this->_template .= '{rows}';
- $this->_template .= "\n".'</table>';
-
- $this->_template_rows = "\n\t".'<tr>';
- $this->_template_rows .= "\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>';
- $this->_template_rows .= "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>';
- $this->_template_rows .= "\n\t".'</tr>';
+ $this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">{rows}'."\n".'</table>';
+
+ $this->_template_rows = "\n\t<tr>\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>'
+ . "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>'."\n\t</tr>";
}
// --------------------------------------------------------------------
@@ -345,30 +324,23 @@ class CI_Unit_test {
*
* Harvests the data within the template {pseudo-variables}
*
- * @access private
* @return void
*/
- function _parse_template()
+ protected function _parse_template()
{
if ( ! is_null($this->_template_rows))
{
return;
}
- if (is_null($this->_template))
+ if (is_null($this->_template) OR ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match))
{
$this->_default_template();
return;
}
- if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match))
- {
- $this->_default_template();
- return;
- }
-
- $this->_template_rows = $match['1'];
- $this->_template = str_replace($match['0'], '{rows}', $this->_template);
+ $this->_template_rows = $match[1];
+ $this->_template = str_replace($match[0], '{rows}', $this->_template);
}
}
@@ -377,8 +349,6 @@ class CI_Unit_test {
/**
* Helper functions to test boolean true/false
*
- *
- * @access private
* @return bool
*/
function is_true($test)