comparison cake/tests/lib/reporter/cake_base_reporter.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:261e66bd5a0c
1 <?php
2 /**
3 * CakeBaseReporter contains common functionality to all cake test suite reporters.
4 *
5 * PHP versions 4 and 5
6 *
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
9 *
10 * Licensed under The Open Group Test Suite License
11 * Redistributions of files must retain the above copyright notice.
12 *
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link http://cakephp.org CakePHP(tm) Project
15 * @package cake
16 * @subpackage cake.tests.libs.reporter
17 * @since CakePHP(tm) v 1.3
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
19 */
20
21 /**
22 * CakeBaseReporter contains common reporting features used in the CakePHP Test suite
23 *
24 * @package cake
25 * @subpackage cake.tests.lib
26 */
27 class CakeBaseReporter extends SimpleReporter {
28
29 /**
30 * Time the test runs started.
31 *
32 * @var integer
33 * @access protected
34 */
35 var $_timeStart = 0;
36
37 /**
38 * Time the test runs ended
39 *
40 * @var integer
41 * @access protected
42 */
43 var $_timeEnd = 0;
44
45 /**
46 * Duration of all test methods.
47 *
48 * @var integer
49 * @access protected
50 */
51 var $_timeDuration = 0;
52
53 /**
54 * Array of request parameters. Usually parsed GET params.
55 *
56 * @var array
57 */
58 var $params = array();
59
60 /**
61 * Character set for the output of test reporting.
62 *
63 * @var string
64 * @access protected
65 */
66 var $_characterSet;
67
68 /**
69 * Does nothing yet. The first output will
70 * be sent on the first test start.
71 *
72 * ### Params
73 *
74 * - show_passes - Should passes be shown
75 * - plugin - Plugin test being run?
76 * - app - App test being run.
77 * - case - The case being run
78 * - codeCoverage - Whether the case/group being run is being code covered.
79 *
80 * @param string $charset The character set to output with. Defaults to UTF-8
81 * @param array $params Array of request parameters the reporter should use. See above.
82 * @access public
83 */
84 function CakeBaseReporter($charset = 'utf-8', $params = array()) {
85 $this->SimpleReporter();
86 if (!$charset) {
87 $charset = 'utf-8';
88 }
89 $this->_characterSet = $charset;
90 $this->params = $params;
91 }
92
93 /**
94 * Signals / Paints the beginning of a TestSuite executing.
95 * Starts the timer for the TestSuite execution time.
96 *
97 * @param string $test_name Name of the test that is being run.
98 * @param integer $size
99 * @return void
100 */
101 function paintGroupStart($test_name, $size) {
102 if (empty($this->_timeStart)) {
103 $this->_timeStart = $this->_getTime();
104 }
105 parent::paintGroupStart($test_name, $size);
106 }
107
108 /**
109 * Signals/Paints the end of a TestSuite. All test cases have run
110 * and timers are stopped.
111 *
112 * @param string $test_name Name of the test that is being run.
113 * @return void
114 */
115 function paintGroupEnd($test_name) {
116 $this->_timeEnd = $this->_getTime();
117 $this->_timeDuration = $this->_timeEnd - $this->_timeStart;
118 parent::paintGroupEnd($test_name);
119 }
120
121 /**
122 * Paints the beginning of a test method being run. This is used
123 * to start/resume the code coverage tool.
124 *
125 * @param string $method The method name being run.
126 * @return void
127 */
128 function paintMethodStart($method) {
129 parent::paintMethodStart($method);
130 if (!empty($this->params['codeCoverage'])) {
131 CodeCoverageManager::start();
132 }
133 }
134
135 /**
136 * Paints the end of a test method being run. This is used
137 * to pause the collection of code coverage if its being used.
138 *
139 * @param string $method The name of the method being run.
140 * @return void
141 */
142 function paintMethodEnd($method) {
143 parent::paintMethodEnd($method);
144 if (!empty($this->params['codeCoverage'])) {
145 CodeCoverageManager::stop();
146 }
147 }
148
149 /**
150 * Get the current time in microseconds. Similar to getMicrotime in basics.php
151 * but in a separate function to reduce dependancies.
152 *
153 * @return float Time in microseconds
154 * @access protected
155 */
156 function _getTime() {
157 list($usec, $sec) = explode(' ', microtime());
158 return ((float)$sec + (float)$usec);
159 }
160
161 /**
162 * Retrieves a list of test cases from the active Manager class,
163 * displaying it in the correct format for the reporter subclass
164 *
165 * @return mixed
166 */
167 function testCaseList() {
168 $testList = TestManager::getTestCaseList();
169 return $testList;
170 }
171
172 /**
173 * Retrieves a list of group test cases from the active Manager class
174 * displaying it in the correct format for the reporter subclass.
175 *
176 * @return void
177 */
178 function groupTestList() {
179 $testList = TestManager::getGroupTestList();
180 return $testList;
181 }
182
183 /**
184 * Paints the start of the response from the test suite.
185 * Used to paint things like head elements in an html page.
186 *
187 * @return void
188 */
189 function paintDocumentStart() {
190
191 }
192
193 /**
194 * Paints the end of the response from the test suite.
195 * Used to paint things like </body> in an html page.
196 *
197 * @return void
198 */
199 function paintDocumentEnd() {
200
201 }
202
203 /**
204 * Paint a list of test sets, core, app, and plugin test sets
205 * available.
206 *
207 * @return void
208 */
209 function paintTestMenu() {
210
211 }
212
213 /**
214 * Get the baseUrl if one is available.
215 *
216 * @return string The base url for the request.
217 */
218 function baseUrl() {
219 if (!empty($_SERVER['PHP_SELF'])) {
220 return $_SERVER['PHP_SELF'];
221 }
222 return '';
223 }
224
225 }