3 * base include file for SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: reporter.php,v 1.31 2004/08/04 22:09:39 lastcraft Exp $
10 * include other SimpleTest class files
12 require_once(dirname(__FILE__
) . '/scorer.php');
16 * Sample minimal test displayer. Generates only
17 * failure messages and a pass count.
19 * @subpackage UnitTester
21 class HtmlReporter
extends SimpleReporter
{
24 * Does nothing yet. The first output will
25 * be sent on the first test start. For use
29 function HtmlReporter() {
30 $this->SimpleReporter();
34 * Paints the top of the web page setting the
35 * title to the name of the starting test.
36 * @param string $test_name Name class of test.
39 function paintHeader($test_name) {
40 $this->sendNoCacheHeaders();
41 print "<html>\n<head>\n<title>$test_name</title>\n";
42 print "<style type=\"text/css\">\n";
43 print $this->_getCss() . "\n";
45 print "</head>\n<body>\n";
46 print "<h1>$test_name</h1>\n";
51 * Send the headers necessary to ensure the page is
52 * reloaded on every request. Otherwise you could be
53 * scratching your head over out of date test data.
57 function sendNoCacheHeaders() {
58 if (! headers_sent()) {
59 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
60 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
61 header("Cache-Control: no-store, no-cache, must-revalidate");
62 header("Cache-Control: post-check=0, pre-check=0", false
);
63 header("Pragma: no-cache");
68 * Paints the CSS. Add additional styles here.
69 * @return string CSS code as text.
73 return ".fail { color: red; } pre { background-color: lightgray; }";
77 * Paints the end of the test with a summary of
78 * the passes and failures.
79 * @param string $test_name Name class of test.
82 function paintFooter($test_name) {
83 $colour = ($this->getFailCount() +
$this->getExceptionCount() > 0 ?
"red" : "green");
84 print "<div style=\"";
85 print "padding: 8px; margin-top: 1em; background-color: $colour; color: white;";
87 print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
88 print " test cases complete:\n";
89 print "<strong>" . $this->getPassCount() . "</strong> passes, ";
90 print "<strong>" . $this->getFailCount() . "</strong> fails and ";
91 print "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
93 print "</body>\n</html>\n";
97 * Paints the test failure with a breadcrumbs
98 * trail of the nesting test suites below the
100 * @param string $message Failure message displayed in
101 * the context of the other tests.
104 function paintFail($message) {
105 parent
::paintFail($message);
106 print "<span class=\"fail\">Fail</span>: ";
107 $breadcrumb = $this->getTestList();
108 array_shift($breadcrumb);
109 print implode(" -> ", $breadcrumb);
110 print " -> " . htmlentities($message) . "<br />\n";
114 * Paints a PHP error or exception.
115 * @param string $message Message is ignored.
119 function paintException($message) {
120 parent
::paintException($message);
121 print "<span class=\"fail\">Exception</span>: ";
122 $breadcrumb = $this->getTestList();
123 array_shift($breadcrumb);
124 print implode(" -> ", $breadcrumb);
125 print " -> <strong>" . htmlentities($message) . "</strong><br />\n";
129 * Paints formatted text such as dumped variables.
130 * @param string $message Text to show.
133 function paintFormattedMessage($message) {
134 echo '<pre>', htmlentities($message), '</pre>';
139 * Sample minimal test displayer. Generates only
140 * failure messages and a pass count. For command
141 * line use. I've tried to make it look like JUnit,
142 * but I wanted to output the errors as they arrived
143 * which meant dropping the dots.
144 * @package SimpleTest
145 * @subpackage UnitTester
147 class TextReporter
extends SimpleReporter
{
150 * Does nothing yet. The first output will
151 * be sent on the first test start.
154 function TextReporter() {
155 $this->SimpleReporter();
159 * Paints the title only.
160 * @param string $test_name Name class of test.
163 function paintHeader($test_name) {
164 if (!SimpleReporter
::inCli()) {
165 header('Content-type: text/plain');
167 print "$test_name\n";
172 * Paints the end of the test with a summary of
173 * the passes and failures.
174 * @param string $test_name Name class of test.
177 function paintFooter($test_name) {
178 if ($this->getFailCount() +
$this->getExceptionCount() == 0) {
181 print "FAILURES!!!\n";
183 print "Test cases run: " . $this->getTestCaseProgress() .
184 "/" . $this->getTestCaseCount() .
185 ", Passes: " . $this->getPassCount() .
186 ", Failures: " . $this->getFailCount() .
187 ", Exceptions: " . $this->getExceptionCount() . "\n";
192 * Paints the test failure as a stack trace.
193 * @param string $message Failure message displayed in
194 * the context of the other tests.
197 function paintFail($message) {
198 parent
::paintFail($message);
199 print $this->getFailCount() . ") $message\n";
200 $breadcrumb = $this->getTestList();
201 array_shift($breadcrumb);
202 print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
207 * Paints a PHP error or exception.
208 * @param string $message Message is ignored.
212 function paintException($message) {
213 parent
::paintException($message);
214 print "Exception " . $this->getExceptionCount() . "!\n$message\n";
218 * Paints formatted text such as dumped variables.
219 * @param string $message Text to show.
222 function paintFormattedMessage($message) {