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

  1. <?php
  2.  
  3. /**
  4.  * TestUnit runs a TestSuite and returns a TestResult object.
  5.  * And more than PHPUnit attach a listener to TestResult. 
  6.  *
  7.  * @version    $Id: TestUnit.php,v 1.1 2003/10/14 04:31:39 cellog Exp $
  8.  * @author     Laurent Laville <pear@laurent-laville.org>
  9.  * @package    HTML_CSS
  10.  */
  11.  
  12. require_once 'PHPUnit.php';
  13.  
  14. class TestUnit extends PHPUnit {
  15.  
  16.     function &run(&$suite, $listener) {
  17.         $result = new TestResult();
  18.     $result->addListener($listener);
  19.         $suite->run($result);
  20.  
  21.         return $result;
  22.     }
  23. }
  24.  
  25. class TestResult extends PHPUnit_TestResult {
  26.  
  27.     /* report result of test run */
  28.     function report() {
  29.     echo "</TABLE>";
  30.  
  31.     $nRun = $this->runCount();
  32.     $nErrors = $this->errorCount();
  33.     $nFailures = $this->failureCount();
  34.     echo "<h2>Summary</h2>";
  35.  
  36.     printf("<p>%s test%s run.<br>", $nRun, ($nRun > 1) ? 's' : '');
  37.     printf("%s error%s.<br>\n", $nErrors, ($nErrors > 1) ? 's' : '');
  38.     printf("%s failure%s.<br>\n", $nFailures, ($nFailures > 1) ? 's' : '');
  39.     if ($nFailures > 0) {
  40.         echo "<h2>Failure Details</h2>";
  41.             print("<ol>\n");
  42.             $failures = $this->failures();
  43.             while (list($i, $failure) = each($failures)) {
  44.                 $failedTest = $failure->failedTest();
  45.                 printf("<li>%s\n", $failedTest->getName() );
  46.                 print("<ul>");
  47.                 printf("<li>%s\n", $failure->thrownException() );
  48.                 print("</ul>");
  49.             }
  50.             print("</ol>\n");
  51.     }
  52.     }
  53.  
  54. }
  55. ?>
  56.