-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMY_Unit_test.php
More file actions
97 lines (81 loc) · 2.26 KB
/
MY_Unit_test.php
File metadata and controls
97 lines (81 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Overloaded CI Unit Test class
*
* @author Istvan Pusztai
* @version $Id: MY_Unit_test.php 6 2009-09-17 07:47:35Z Istvan $
* @copyright Copyright (C) 2009 Istvan Pusztai (twitter.com/istvanp)
**/
class MY_Unit_test extends CI_Unit_Test
{
var $CI;
function __construct()
{
parent::__construct();
$this->CI =& get_instance();
}
/**
* Run the tests
*
* Runs the supplied tests
*
* @access public
* @param mixed
* @param mixed
* @param string
* @param bool
* @return string
*/
function run($test, $expected = TRUE, $test_name = 'undefined', $is_model = NULL)
{
if ($this->active == FALSE)
{
return FALSE;
}
if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE))
{
$expected = str_replace('is_float', 'is_double', $expected);
$result = ($expected($test)) ? TRUE : FALSE;
$extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected));
}
else
{
if ($this->strict == TRUE)
$result = ($test === $expected) ? TRUE : FALSE;
else
$result = ($test == $expected) ? TRUE : FALSE;
$extype = gettype($expected);
}
$sql_error = '';
$sql_query = '';
if ($is_model === NULL && strripos($test_name, "model") !== FALSE)
{
$is_model = TRUE;
}
if ($is_model == TRUE && $result === FALSE)
{
$sql_error = $this->CI->db->_error_message();
if (empty($sql_error))
{
$sql_error = "Query affected " . $this->CI->db->affected_rows() . " row(s)";
}
$sql_query = $this->CI->db->last_query();
}
$back = $this->_backtrace();
$report[] = array (
'test_name' => $test_name,
'test_datatype' => gettype($test),
'test_value' => $test,
'res_datatype' => $extype,
'res_value' => $expected,
'res_sql_error' => $sql_error,
'res_sql_query' => $sql_query,
'result' => ($result === TRUE) ? 'passed' : 'failed',
'file' => $back['file'],
'line' => $back['line']
);
$this->results[] = $report;
return($this->report($this->result($report)));
}
}
/* End of file MY_Unit_test.php */