3 * base include file for SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: scorer.php,v 1.2 2004/08/04 23:48:51 lastcraft Exp $
10 * Can recieve test events and display them. Display
11 * is achieved by making display methods available
12 * and visiting the incoming event.
14 * @subpackage UnitTester
24 * Starts the test run with no results.
27 function SimpleScorer() {
30 $this->_exceptions
= 0;
31 $this->_is_dry_run
= false
;
35 * Signals that the next evaluation will be a dry
36 * run. That is, the structure events will be
37 * recorded, but no tests will be run.
39 function makeDry($is_dry = true
) {
40 $this->_is_dry_run
= $is_dry;
44 * Invokes a single test method on the test case.
45 * This call back allows the reporter to decide if
46 * it actually wants to run the test.
47 * @param SimpleRunner $runner Test case to run test on.
48 * @param string $method Name of test method.
51 function invoke(&$runner, $method) {
52 if (! $this->_is_dry_run
) {
53 $runner->invoke($method);
58 * Accessor for current status. Will be false
59 * if there have been any failures or exceptions.
60 * Used for command line tools.
61 * @return boolean True if no failures.
64 function getStatus() {
65 if ($this->_exceptions +
$this->_fails
> 0) {
72 * Paints the start of a test method.
73 * @param string $test_name Name of test or other label.
76 function paintMethodStart($test_name) {
80 * Paints the end of a test method.
81 * @param string $test_name Name of test or other label.
84 function paintMethodEnd($test_name) {
88 * Paints the start of a test case.
89 * @param string $test_name Name of test or other label.
92 function paintCaseStart($test_name) {
96 * Paints the end of a test case.
97 * @param string $test_name Name of test or other label.
100 function paintCaseEnd($test_name) {
104 * Paints the start of a group test.
105 * @param string $test_name Name of test or other label.
106 * @param integer $size Number of test cases starting.
109 function paintGroupStart($test_name, $size) {
113 * Paints the end of a group test.
114 * @param string $test_name Name of test or other label.
117 function paintGroupEnd($test_name) {
121 * Increments the pass count.
122 * @param string $message Message is ignored.
125 function paintPass($message) {
130 * Increments the fail count.
131 * @param string $message Message is ignored.
134 function paintFail($message) {
139 * Deals with PHP 4 throwing an error.
140 * @param string $message Text of error formatted by
144 function paintError($message) {
145 $this->paintException($message);
149 * Deals with PHP 5 throwing an exception
150 * This isn't really implemented yet.
151 * @param Exception $exception Object thrown.
154 function paintException($exception) {
155 $this->_exceptions++
;
159 * Accessor for the number of passes so far.
160 * @return integer Number of passes.
163 function getPassCount() {
164 return $this->_passes
;
168 * Accessor for the number of fails so far.
169 * @return integer Number of fails.
172 function getFailCount() {
173 return $this->_fails
;
177 * Accessor for the number of untrapped errors
179 * @return integer Number of exceptions.
182 function getExceptionCount() {
183 return $this->_exceptions
;
187 * Paints a simple supplementary message.
188 * @param string $message Text to display.
191 function paintMessage($message) {
195 * Paints a formatted ASCII message such as a
197 * @param string $message Text to display.
200 function paintFormattedMessage($message) {
204 * By default just ignores user generated events.
205 * @param string $type Event type as text.
206 * @param mixed $payload Message or object.
209 function paintSignal($type, &$payload) {
214 * Recipient of generated test messages that can display
215 * page footers and headers. Also keeps track of the
216 * test nesting. This is the main base class on which
217 * to build the finished test (page based) displays.
218 * @package SimpleTest
219 * @subpackage UnitTester
221 class SimpleReporter
extends SimpleScorer
{
227 * Starts the display with no results in.
230 function SimpleReporter() {
231 $this->SimpleScorer();
232 $this->_test_stack
= array();
234 $this->_progress
= 0;
238 * Paints the start of a group test. Will also paint
239 * the page header and footer if this is the
240 * first test. Will stash the size if the first
242 * @param string $test_name Name of test that is starting.
243 * @param integer $size Number of test cases starting.
246 function paintGroupStart($test_name, $size) {
247 if (! isset($this->_size
)) {
248 $this->_size
= $size;
250 if (count($this->_test_stack
) == 0) {
251 $this->paintHeader($test_name);
253 $this->_test_stack
[] = $test_name;
257 * Paints the end of a group test. Will paint the page
258 * footer if the stack of tests has unwound.
259 * @param string $test_name Name of test that is ending.
260 * @param integer $progress Number of test cases ending.
263 function paintGroupEnd($test_name) {
264 array_pop($this->_test_stack
);
265 if (count($this->_test_stack
) == 0) {
266 $this->paintFooter($test_name);
271 * Paints the start of a test case. Will also paint
272 * the page header and footer if this is the
273 * first test. Will stash the size if the first
275 * @param string $test_name Name of test that is starting.
278 function paintCaseStart($test_name) {
279 if (! isset($this->_size
)) {
282 if (count($this->_test_stack
) == 0) {
283 $this->paintHeader($test_name);
285 $this->_test_stack
[] = $test_name;
289 * Paints the end of a test case. Will paint the page
290 * footer if the stack of tests has unwound.
291 * @param string $test_name Name of test that is ending.
294 function paintCaseEnd($test_name) {
296 array_pop($this->_test_stack
);
297 if (count($this->_test_stack
) == 0) {
298 $this->paintFooter($test_name);
303 * Paints the start of a test method.
304 * @param string $test_name Name of test that is starting.
307 function paintMethodStart($test_name) {
308 $this->_test_stack
[] = $test_name;
312 * Paints the end of a test method. Will paint the page
313 * footer if the stack of tests has unwound.
314 * @param string $test_name Name of test that is ending.
317 function paintMethodEnd($test_name) {
318 array_pop($this->_test_stack
);
322 * Paints the test document header.
323 * @param string $test_name First test top level
328 function paintHeader($test_name) {
332 * Paints the test document footer.
333 * @param string $test_name The top level test.
337 function paintFooter($test_name) {
341 * Accessor for internal test stack. For
342 * subclasses that need to see the whole test
343 * history for display purposes.
344 * @return array List of methods in nesting order.
347 function getTestList() {
348 return $this->_test_stack
;
352 * Accessor for total test size in number
353 * of test cases. Null until the first
355 * @return integer Total number of cases at start.
358 function getTestCaseCount() {
363 * Accessor for the number of test cases
365 * @return integer Number of ended cases.
368 function getTestCaseProgress() {
369 return $this->_progress
;
373 * Static check for running in the comand line.
374 * @return boolean True if CLI.
379 return php_sapi_name() == 'cli';