/** * Run a test */ public function run(PHPUnit_Framework_TestSuite $suite) { $res = new PHPUnit_Framework_TestResult(); if ($this->codecoverage) { $res->collectCodeCoverageInformation(TRUE); } $res->addListener($this); foreach ($this->formatters as $formatter) { $res->addListener($formatter); } /* Set PHPUnit error handler */ if ($this->useCustomErrorHandler) { $oldErrorHandler = set_error_handler(array('PHPUnitTestRunner', 'handleError'), E_ALL | E_STRICT); } $suite->run($res, false, $this->groups, $this->excludeGroups); foreach ($this->formatters as $formatter) { $formatter->processResult($res); } /* Restore Phing error handler */ if ($this->useCustomErrorHandler) { restore_error_handler(); } if ($this->codecoverage) { $coverageInformation = $res->getCodeCoverageInformation(); PHPUnit_Util_CodeCoverage::clearSummary(); $summary = PHPUnit_Util_CodeCoverage::getSummary($coverageInformation); CoverageMerger::merge($this->project, $summary); } if ($res->errorCount() != 0) { $this->retCode = self::ERRORS; } else { if ($res->failureCount() != 0) { $this->retCode = self::FAILURES; } else { if ($res->notImplementedCount() != 0) { $this->retCode = self::INCOMPLETES; } else { if ($res->skippedCount() != 0) { $this->retCode = self::SKIPPED; } } } } }
/** * Renders the report. * * @param PHPUnit_Framework_TestResult $result * @param string $title * @param string $target * @param string $charset * @param boolean $yui * @param boolean $highlight * @param integer $lowUpperBound * @param integer $highLowerBound */ public static function render(PHPUnit_Framework_TestResult $result, $target, $title = '', $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70) { $target = PHPUnit_Util_Filesystem::getDirectory($target); self::$templatePath = sprintf('%s%sReport%sTemplate%s', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); $codeCoverageInformation = $result->getCodeCoverageInformation(); $files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation); $commonPath = PHPUnit_Util_Filesystem::reducePaths($files); $items = self::buildDirectoryStructure($files); unset($codeCoverageInformation); if ($title == '') { $topTestSuite = $result->topTestSuite(); if ($topTestSuite instanceof PHPUnit_Framework_TestSuite) { $title = $topTestSuite->getName(); } } unset($result); $root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL); self::addItems($root, $items, $files, $yui, $highlight); self::copyFiles($target); PHPUnit_Util_CodeCoverage::clearSummary(); $root->render($target, $title, $charset, $lowUpperBound, $highLowerBound); }