forked from simpletest/simpletest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolortext_reporter.php
69 lines (62 loc) · 1.47 KB
/
colortext_reporter.php
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
<?php
require_once dirname(__FILE__) . '/../reporter.php';
/**
* Provides an ANSI-colored {@link TextReporter} for viewing test results.
*
* @author Jason Sweat (original code)
* @author Travis Swicegood <development@domain51.com>
*/
class ColorTextReporter extends TextReporter
{
public $_failColor = 41;
public $_passColor = 42;
/**
* Handle initialization
*
* @param {@link TextReporter}
*/
public function __construct()
{
parent::__construct();
}
/**
* Capture the attempt to display the final test results
* and insert the ANSI-color codes in place.
*
* @param string
*
* @see TextReporter
*/
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
*/
public function _setColor($color)
{
printf("%s[%sm\n", chr(27), $color);
}
/**
* Resets the color back to normal.
*/
public function _resetColor()
{
$this->_setColor(0);
}
}