home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / HTML_TestListener.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  1.8 KB  |  64 lines

  1. <?php
  2.  
  3. /**
  4.  * Provides a nice HTML output for PHPUnit suite tests.
  5.  * 
  6.  * @version    $Id: HTML_TestListener.php,v 1.1 2003/10/14 04:31:39 cellog Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_CSS
  9.  */
  10.  
  11. class HTML_TestListener extends PHPUnit_TestListener {
  12.  
  13.     function HTML_TestListener() {
  14.  
  15. $report = <<<EOS
  16. <table cellspacing="1" cellpadding="1" border="0" width="90%" align="center" class="details">
  17. <tr><th>Class</th><th>Function</th><th>Success</th><th>Meta-result</th></tr>
  18. EOS;
  19.         echo $report;
  20.     }
  21.  
  22.     function addError(&$test, &$t) {
  23.         $this->_errors += 1;
  24.     }
  25.  
  26.     function addFailure(&$test, &$t) {
  27.         $this->_fails += 1;
  28.     }
  29.  
  30.     function endTest(&$test) {
  31.     /* Report both the test result and, for this special situation
  32.        where some tests are expected to fail, a "meta" test result
  33.        which indicates whether the test result matches the
  34.        expected result. 
  35.      */
  36.     $expect_failure = preg_match('/fail/i', $test->getName());
  37.     $test_passed = ($this->_fails == 0 && $this->_errors == 0);
  38.  
  39.     if ($this->_errors > 0) {
  40.         $outcome = "<span class=\"Error\">ERROR</span>";
  41.     } else if ($this->_fails > 0) {
  42.         $outcome = "<span class=\"Failure\">FAIL</span>";
  43.     } else {
  44.         $outcome = "<span class=\"Pass\">OK</span>";
  45.         }
  46.     if ($this->_errors > 0) {
  47.         $meta_outcome = '<span class="Unknown">unknown</span>';
  48.     } else {
  49.         $meta_outcome = ($expect_failure xor $test_passed)
  50.         ? '<span class="Expected">as expected</span>'
  51.         : '<span class="Unexpected">UNEXPECTED</span>';
  52.         }
  53.     printf("<td>$outcome</td><td>$meta_outcome</td></tr>");
  54.     }
  55.  
  56.     function startTest(&$test) {
  57.         $this->_fails = 0;
  58.         $this->_errors = 0;
  59.         printf("<tr><td>%s </td><td>%s </td>", get_class($test), $test->getName());
  60.     }
  61.  
  62.  
  63. }
  64. ?>