| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* SVN FILE: $Id: cli_reporter.php 7945 2008-12-19 02:16:01Z gwoo $ */
|
|
|
3 |
/**
|
|
|
4 |
* Short description for file.
|
|
|
5 |
*
|
|
|
6 |
* Long description for file
|
|
|
7 |
*
|
|
|
8 |
* PHP versions 4 and 5
|
|
|
9 |
*
|
|
|
10 |
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
11 |
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
12 |
*
|
|
|
13 |
* Licensed under The Open Group Test Suite License
|
|
|
14 |
* Redistributions of files must retain the above copyright notice.
|
|
|
15 |
*
|
|
|
16 |
* @filesource
|
|
|
17 |
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
18 |
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
19 |
* @package cake
|
|
|
20 |
* @subpackage cake.cake.tests.libs
|
|
|
21 |
* @since CakePHP(tm) v 1.2.0.4433
|
|
|
22 |
* @version $Revision: 7945 $
|
|
|
23 |
* @modifiedby $LastChangedBy: gwoo $
|
|
|
24 |
* @lastmodified $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
|
|
|
25 |
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
26 |
*/
|
|
|
27 |
if (! defined('ST_FAILDETAIL_SEPARATOR')) {
|
|
|
28 |
define('ST_FAILDETAIL_SEPARATOR', "->");
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
if (version_compare(PHP_VERSION, '4.4.4', '<=') ||
|
|
|
32 |
PHP_SAPI == 'cgi') {
|
|
|
33 |
define('STDOUT', fopen('php://stdout', 'w'));
|
|
|
34 |
define('STDERR', fopen('php://stderr', 'w'));
|
|
|
35 |
register_shutdown_function(create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
|
|
|
36 |
}
|
|
|
37 |
/**
|
|
|
38 |
* Minimal command line test displayer. Writes fail details to STDERR. Returns 0
|
|
|
39 |
* to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails.
|
|
|
40 |
*
|
|
|
41 |
* @package cake
|
|
|
42 |
* @subpackage cake.cake.tests.libs
|
|
|
43 |
*/
|
|
|
44 |
class CLIReporter extends TextReporter {
|
|
|
45 |
var $faildetail_separator = ST_FAILDETAIL_SEPARATOR;
|
|
|
46 |
|
|
|
47 |
function CLIReporter($faildetail_separator = NULL) {
|
|
|
48 |
$this->SimpleReporter();
|
|
|
49 |
if (! is_null($faildetail_separator)) {
|
|
|
50 |
$this->setFailDetailSeparator($faildetail_separator);
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
function setFailDetailSeparator($separator) {
|
|
|
55 |
$this->faildetail_separator = $separator;
|
|
|
56 |
}
|
|
|
57 |
/**
|
|
|
58 |
* Return a formatted faildetail for printing.
|
|
|
59 |
*/
|
|
|
60 |
function &_paintTestFailDetail(&$message) {
|
|
|
61 |
$buffer = '';
|
|
|
62 |
$faildetail = $this->getTestList();
|
|
|
63 |
array_shift($faildetail);
|
|
|
64 |
$buffer .= implode($this->faildetail_separator, $faildetail);
|
|
|
65 |
$buffer .= $this->faildetail_separator . "$message\n";
|
|
|
66 |
return $buffer;
|
|
|
67 |
}
|
|
|
68 |
/**
|
|
|
69 |
* Paint fail faildetail to STDERR.
|
|
|
70 |
*/
|
|
|
71 |
function paintFail($message) {
|
|
|
72 |
parent::paintFail($message);
|
|
|
73 |
fwrite(STDERR, 'FAIL' . $this->faildetail_separator . $this->_paintTestFailDetail($message));
|
|
|
74 |
}
|
|
|
75 |
/**
|
|
|
76 |
* Paint exception faildetail to STDERR.
|
|
|
77 |
*/
|
|
|
78 |
function paintException($message) {
|
|
|
79 |
parent::paintException($message);
|
|
|
80 |
fwrite(STDERR, 'EXCEPTION' . $this->faildetail_separator . $this->_paintTestFailDetail($message));
|
|
|
81 |
}
|
|
|
82 |
/**
|
|
|
83 |
* Paint a footer with test case name, timestamp, counts of fails and exceptions.
|
|
|
84 |
*/
|
|
|
85 |
function paintFooter($test_name) {
|
|
|
86 |
$buffer = $this->getTestCaseProgress() . '/' . $this->getTestCaseCount() . ' test cases complete: ';
|
|
|
87 |
|
|
|
88 |
if (0 < ($this->getFailCount() + $this->getExceptionCount())) {
|
|
|
89 |
$buffer .= $this->getPassCount() . " passes";
|
|
|
90 |
if (0 < $this->getFailCount()) {
|
|
|
91 |
$buffer .= ", " . $this->getFailCount() . " fails";
|
|
|
92 |
}
|
|
|
93 |
if (0 < $this->getExceptionCount()) {
|
|
|
94 |
$buffer .= ", " . $this->getExceptionCount() . " exceptions";
|
|
|
95 |
}
|
|
|
96 |
$buffer .= ".\n";
|
|
|
97 |
fwrite(STDOUT, $buffer);
|
|
|
98 |
} else {
|
|
|
99 |
fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n");
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
?>
|