* @license PHP License * @package WB * @subpackage unittest */ WBClass::load('WBClock'); /** * Helper class reporer * * @version 0.1.0 * @package WB * @subpackage unittest */ class WBUnitTest_Reporter extends SimpleReporter { /** * referernce counter * @var int */ static protected $rev = 0; /** * float * @var timestampt */ protected $timestamp; /** * constructor */ public function __construct() { // call parent contrstrutor self::paintHead(); } /** * destructor */ public function __destruct() { self::paintFoot(); } /** * paint HTML header only once */ static protected function paintHead() { ++self::$rev; if (self::$rev > 1) { return; } $html = array(); $html[] = ''; $html[] = ''; $html[] = ''; $html[] = sprintf('Wombat UnitTest'); $html[] = ''; $html[] = ''; $html[] = ''; $html[] = '

Wombat Unit Test

'; echo implode(' ', $html) . "\n"; flush(); } /** * paint HTML footer only once */ static protected function paintFoot() { --self::$rev; if (self::$rev > 0) { return; } $html = array(); $html[] = ''; $html[] = ''; echo implode(' ', $html) . "\n"; flush(); } /** * paint headline for each test case * * @param string $test_name * @see lib/simpletest/SimpleReporter#paintHeader($test_name) */ public function paintHeader($test_name) { $html = array(); $html[] = sprintf('

%s

', $test_name); echo implode(' ', $html) . "\n"; flush(); $this->timestamp = WBClock::now(); } /** * paint footer for each test case * * @param string $test_name * @see lib/simpletest/SimpleReporter#paintFooter($test_name) */ public function paintFooter($test_name) { $cntPass = intval($this->getPassCount()); $cntFail = intval($this->getFailCount()); $cntExcep = intval($this->getExceptionCount()); $class = 'ok'; if ($cntFail + $cntExcep > 0) { $class = 'fail'; } $time = WBClock::stop($this->timestamp, 1000, 2); $html = array(); $html[] = sprintf('
%sms
%d/%d test cases complete:', $class, $time, $this->getTestCaseProgress(), $this->getTestCaseCount()); $html[] = "\n"; $html[] = sprintf('%s %s', $cntPass, 'passes'); $html[] = sprintf('%s %s', $cntFail, 'failed and'); $html[] = sprintf('%s %s', $cntExcep, 'exceptions.'); $html[] = "\n"; $html[] = '
'; echo implode(' ', $html) . "\n"; flush(); } /** * display failure * * @param string message * @see lib/simpletest/SimpleReporter#paintFail($message) */ public function paintFail($message) { parent::paintFail($message); $this->paintBox('fail', 'Fail', $message); } /** * Display Error * * @param string $message * @see lib/simpletest/SimpleReporter#paintException($message) */ public function paintError($message) { parent::paintError($message); $this->paintBox('fail', 'Error', $message); } /** * display Exception * * @param string $message * @see lib/simpletest/SimpleReporter#paintException($message) */ public function paintException($message) { parent::paintException($message); $this->paintBox('fail', 'Exception', $message); } /** * paint generic box * * Auxiliary method that displays div * * @param string $class * @param string $title * @param strring $message */ protected function paintBox($class, $title, $message) { $breadcrumb = $this->getTestList(); array_shift($breadcrumb); $html = array(); $html[] = '' . $title . ':'; $html[] = implode(" -> ", $breadcrumb); $html[] = '-> ' . $this->htmlEntities($message) . ''; $html[] = "
\n"; echo implode(' ', $html) . "\n"; flush(); } /** * paint formatted text such as dumped variables. * * @param string $message * @see lib/simpletest/SimpleReporter#paintFormattedMessage($message) */ public function paintFormattedMessage($message) { echo '
' . $this->htmlEntities($message) . '
'; } /** * character set adjusted entity conversion. * * @param string $message * @return string */ protected function htmlEntities($message) { return htmlentities($message, ENT_COMPAT, 'UTF-8'); } } ?>