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
|
<?php
/**
* Base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
* @version $Id: colortext_reporter.php,v 1.3 2005/08/02 16:06:41 jsweat Exp $
*/
/**
* include base reporter
*/
require_once(dirname(__FILE__) . '/../reporter.php');
/**
* Provides an ANSI-colored {@link TextReporter} for viewing test results.
*
* This code is made available under the same terms as SimpleTest. It is based
* off of code that Jason Sweat originally published on the SimpleTest mailing
* list.
*
* @author Jason Sweat (original code)
* @author Travis Swicegood <development@domain51.com>
* @package SimpleTest
* @subpackage UnitTester
*/
class ColorTextReporter extends TextReporter {
var $_failColor = 41;
var $_passColor = 42;
/**
* Handle initialization
*
* @param {@link TextReporter}
*/
function ColorTextReporter() {
parent::TextReporter();
}
/**
* Capture the attempt to display the final test results and insert the
* ANSI-color codes in place.
*
* @param string
* @see TextReporter
* @access public
*/
function paintFooter($test_name) {
ob_start();
parent::paintFooter($test_name);
$output = trim(ob_get_clean());
if ($output) {
if (($this->getFailCount() + $this->getExceptionCount()) == 0) {
$color = $this->_passColor;
} else {
$color = $this->_failColor;
}
$this->_setColor($color);
echo $output;
$this->_resetColor();
}
}
/**
* Sets the terminal to an ANSI-standard $color
*
* @param int
* @access protected
*/
function _setColor($color) {
printf("%s[%sm\n", chr(27), $color);
}
/**
* Resets the color back to normal.
*
* @access protected
*/
function _resetColor() {
$this->_setColor(0);
}
}
|