3 * Swiped from the WACT test suite
5 * @see http://www.phpwact.org
6 * @version $Id: cli_reporter.php,v 1.1.1.1 2005/07/04 22:30:11 harryf Exp $
8 if (! defined('ST_FAILDETAIL_SEPARATOR')) {
9 define('ST_FAILDETAIL_SEPARATOR', "->");
12 if (! defined('ST_FAILS_RETURN_CODE')) {
13 define('ST_FAILS_RETURN_CODE', 1);
16 if (version_compare(phpversion(), '4.3.0', '<') ||
17 php_sapi_name() == 'cgi') {
18 define('STDOUT', fopen('php://stdout', 'w'));
19 define('STDERR', fopen('php://stderr', 'w'));
20 register_shutdown_function(
21 create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
25 * Minimal command line test displayer. Writes fail details to STDERR. Returns 0
26 * to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails.
28 class CLIReporter extends SimpleReporter {
30 var $faildetail_separator = ST_FAILDETAIL_SEPARATOR;
32 function CLIReporter($faildetail_separator = NULL) {
33 $this->SimpleReporter();
34 if (! is_null($faildetail_separator)) {
35 $this->setFailDetailSeparator($faildetail_separator);
39 function setFailDetailSeparator($separator) {
40 $this->faildetail_separator = $separator;
44 * Return a formatted faildetail for printing.
46 function &_paintTestFailDetail(&$message) {
48 $faildetail = $this->getTestList();
49 array_shift($faildetail);
50 $buffer .= implode($this->faildetail_separator, $faildetail);
51 $buffer .= $this->faildetail_separator . "$message\n";
56 * Paint fail faildetail to STDERR.
58 function paintFail($message) {
59 parent::paintFail($message);
60 fwrite(STDERR, 'FAIL' . $this->faildetail_separator .
61 $this->_paintTestFailDetail($message));
65 * Paint exception faildetail to STDERR.
67 function paintException($message) {
68 parent::paintException($message);
69 fwrite(STDERR, 'EXCEPTION' . $this->faildetail_separator .
70 $this->_paintTestFailDetail($message));
74 * Paint a footer with test case name, timestamp, counts of fails and
77 function paintFooter($test_name) {
78 $buffer = $this->getTestCaseProgress() . '/' .
79 $this->getTestCaseCount() . ' test cases complete: ';
81 if (0 < ($this->getFailCount() + $this->getExceptionCount())) {
82 $buffer .= $this->getPassCount() . " passes";
83 if (0 < $this->getFailCount()) {
84 $buffer .= ", " . $this->getFailCount() . " fails";
86 if (0 < $this->getExceptionCount()) {
87 $buffer .= ", " . $this->getExceptionCount() . " exceptions";
90 fwrite(STDOUT, $buffer);
91 exit(ST_FAILS_RETURN_CODE);
93 fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n");