Miscellaneous
The standard test reporter is very minimalistic. If you want more shiny output to impress someone, fear not, it is actually very easy to extend.
The only danger is that you have to fiddle with core Cake code, specifically /cake/tests/libs/cake_reporter.php.
To change the test output you can override the following methods:
- paintHeader()
- Prints before the test is started.
- paintPass()
- Prints everytime a test case has passed. Use $this->getTestList() to get an array of information pertaining to the test, and $message to get the test result. Remember to call parent::paintPass($message).
- paintFail()
- Prints everytime a test case has failed. Remember to call parent::paintFail($message).
- paintFooter()
- Prints when the test is over, i.e. when all test cases has been executed.
If, when running paintPass and paintFail, you want to hide the parent output, enclose the call in html comment tags, as in:
Простой текстecho "\n<!-- ";parent::paintFail($message);echo " -->\n";
A sample cake_reporter.php setup that creates a table to hold the test results follows:
Простой текст<?php/*** CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>* Copyright 2005-2008, Cake Software Foundation, Inc.* 1785 E. Sahara Avenue, Suite 490-204* Las Vegas, Nevada 89104** Licensed under The Open Group Test Suite License* Redistributions of files must retain the above copyright notice.*/class CakeHtmlReporter extends HtmlReporter {function CakeHtmlReporter($characterSet = 'UTF-8') {parent::HtmlReporter($characterSet);}function paintHeader($testName) {$this->sendNoCacheHeaders();$baseUrl = BASE;print "<h2>$testName</h2>\n";print "<table style=\"\"><th>Res.</th><th>Test case</th><th>Message</th>\n";flush();}function paintFooter($testName) {$colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");print "</table>\n";print "<div style=\"";print "padding: 8px; margin-top: 1em; background-color: $colour; color: white;";print "\">";print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();print " test cases complete:\n";print "<strong>" . $this->getPassCount() . "</strong> passes, ";print "<strong>" . $this->getFailCount() . "</strong> fails and ";print "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";print "</div>\n";}function paintPass($message) {parent::paintPass($message);echo "<tr>\n\t<td width=\"20\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";print "\t\t<span style=\"color: green;\">Pass</span>: \n";echo "\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";$breadcrumb = $this->getTestList();array_shift($breadcrumb);array_shift($breadcrumb);print implode("->", $breadcrumb);echo "\n\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";$message = split('at \[', $message);print "->$message[0]<br />\n\n";echo "\n\t</td>\n</tr>\n\n";}function paintFail($message) {echo "\n<!-- ";parent::paintFail($message);echo " -->\n";echo "<tr>\n\t<td width=\"20\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";print "\t\t<span style=\"color: red;\">Fail</span>: \n";echo "\n\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";$breadcrumb = $this->getTestList();print implode("->", $breadcrumb);echo "\n\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";print "$message";echo "\n\t</td>\n</tr>\n\n";}function _getCss() {return parent::_getCss() . ' .pass { color: green; }';}}?>


Коментарии:
Добавить коментарий