12 require_once dirname(__FILE__).
'/../reporter.php';
23 function __construct() {
24 parent::__construct();
25 $this->doc =
new DOMDocument();
26 $this->doc->loadXML(
'<testsuite/>');
27 $this->root = $this->doc->documentElement;
30 function paintHeader($test_name) {
31 $this->testsStart = microtime(
true);
33 $this->root->setAttribute(
'name', $test_name);
34 $this->root->setAttribute(
'timestamp', date(
'c'));
35 $this->root->setAttribute(
'hostname',
'localhost');
37 echo
"<?xml version=\"1.0\"?>\n";
38 echo
"<!-- starting test suite $test_name\n";
49 echo
"\n<testsuites>\n";
51 $duration = microtime(
true) - $this->testsStart;
53 $this->root->setAttribute(
'tests', $this->getPassCount() + $this->getFailCount() + $this->getExceptionCount());
54 $this->root->setAttribute(
'failures', $this->getFailCount());
55 $this->root->setAttribute(
'errors', $this->getExceptionCount());
56 $this->root->setAttribute(
'time', $duration);
58 $this->doc->formatOutput =
true;
59 $xml = $this->doc->saveXML();
61 echo preg_replace(
'/<\?[^>]*\?>/',
"", $xml);
62 echo
"</testsuites>\n";
65 function paintCaseStart($case) {
66 echo
"- case start $case\n";
67 $this->currentCaseName = $case;
70 function paintCaseEnd($case) {
74 function paintMethodStart($test) {
75 echo
" - test start: $test\n";
77 $this->methodStart = microtime(
true);
78 $this->currCase = $this->doc->createElement(
'testcase');
81 function paintMethodEnd($test) {
82 $duration = microtime(
true) - $this->methodStart;
84 $this->currCase->setAttribute(
'name', $test);
85 $this->currCase->setAttribute(
'classname', $this->currentCaseName);
86 $this->currCase->setAttribute(
'time', $duration);
87 $this->root->appendChild($this->currCase);
90 function paintFail($message) {
91 parent::paintFail($message);
93 error_log(
"Failure: " . $message);
94 $this->terminateAbnormally($message);
97 function paintException($exception) {
98 parent::paintException($exception);
100 error_log(
"Exception: " . $exception);
101 $this->terminateAbnormally($exception);
104 function terminateAbnormally($message) {
105 if (!$this->currCase) {
106 error_log(
"!! currCase was not set.");
110 $ch = $this->doc->createElement(
'failure');
111 $breadcrumb = $this->getTestList();
112 $ch->setAttribute(
'message', $breadcrumb[count($breadcrumb)-1]);
113 $ch->setAttribute(
'type', $breadcrumb[count($breadcrumb)-1]);
115 $message = implode(
' -> ', $breadcrumb) .
"\n\n\n" . $message;
116 $content = $this->doc->createTextNode($message);
117 $ch->appendChild($content);
119 $this->currCase->appendChild($ch);