$result = new PHPUnit2_Framework_TestResult; * $result->addListener(new ISI_PHPUnit2_Output_HTML_Listener); * $suite->run($result); * * @author Iris Studios, Inc. * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc. * @version $Revision$ * */ class ISI_PHPUnit2_Output_HTML_Listener implements PHPUnit2_Framework_TestListener { /** * A successful test * @var integer */ const TEST_SUCCESS = 1; /** * An incomplete test * @var integer */ const TEST_INCOMPLETE = 2; /** * A failed test * @var integer */ const TEST_FAIL = 3; /** * An array of all the tests run in a given suite * @var array */ protected $tests = array(); /** * An array of arrays of all the errors in a given failed test in a suite * @var array */ protected $errors = array(); /** * An array of all the incomplete test messages for a test in a suite * @var array */ protected $incompletes = array(); /** * Statistics for a given test suite * @var array */ protected $stats = array(); /** * The name of the currently-running test suite * @var string */ private $currentSuite; /** * The name of the currently-running individual test * @var string */ private $currentTest; // ################################################################### /** * A test errored out * * @param object PHPUnit2_Framework_Test * @param except Thrown execption */ public function addError(PHPUnit2_Framework_Test $test, Exception $e) { $this->errors[ $this->currentSuite ][ $this->currentTest ][] = new ISI_Private_Exception($e); } // ################################################################### /** * A test failed * * @param object PHPUnit2_Framework_Test * @param object PHPUnit2_Framework_AssertionFailedError */ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { $this->errors[ $this->currentSuite ][ $this->currentTest ][] = new ISI_Private_Exception($e); $this->tests[ $this->currentSuite ][ $this->currentTest ] = self::TEST_FAIL; $this->stats[ $this->currentSuite ]['fail']++; } // ################################################################### /** * A test reported being an incomplete implementation * * @param object PHPUnit2_Framework_Test * @param except The thrown exception notice */ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { $this->incompletes[ $this->currentSuite ][ $this->currentTest ] = new ISI_Private_Exception($e); $this->tests[ $this->currentSuite ][ $this->currentTest ] = self::TEST_INCOMPLETE; $this->stats[ $this->currentSuite ]['incomplete']++; } // ################################################################### /** * Start test suite * * @param object A PHPUnit2_Framework_TestSuite */ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { $this->currentSuite = $suite->getName(); if ($this->currentSuite == '') { return; } $this->tests[ $this->currentSuite ] = array(); $this->stats[ $this->currentSuite ] = array('total' => 0, 'fail' => 0, 'incomplete' => 0); } // ################################################################### /** * Test suite ended * * @param object PHPUnit2_Framework_TestSuite */ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { $this->currentSuite = null; } // ################################################################### /** * An individual test started * * @param object The PHPUnit2_Framework_Test */ public function startTest(PHPUnit2_Framework_Test $test) { $this->currentTest = $test->getName(); if ($this->currentTest == '') { return; } $this->tests[ $this->currentSuite ][ $this->currentTest ] = self::TEST_SUCCESS; $this->stats[ $this->currentSuite ]['total']++; } // ################################################################### /** * An individual test ended * * @param object The PHPUnit2_Framework_Test */ public function endTest(PHPUnit2_Framework_Test $test) { $this->currentTest = null; } // ################################################################### /** * Destructor: create the HTML output */ public function __destruct() { $stats = array('total' => 0, 'incomplete' => 0, 'fail' => 0, 'success' => 0); foreach ($this->stats AS $statGroup) { foreach ($statGroup AS $statType => $count) { $stats["$statType"] += $count; } } $stats['success'] = $stats['total'] - ($stats['incomplete'] + $stats['fail']); $output = '