/**
  * @param PHPUnit_Framework_Test $suite
  * @param array                  $arguments
  * @param bool                   $exit
  *
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = [], $exit = true)
 {
     if (isset($arguments['configuration'])) {
         $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] = $arguments['configuration'];
     }
     $this->handleConfiguration($arguments);
     $this->processSuiteFilters($suite, $arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === true) {
         $suite->setBackupGlobals(true);
     }
     if ($arguments['backupStaticAttributes'] === true) {
         $suite->setBackupStaticAttributes(true);
     }
     if ($arguments['beStrictAboutChangesToGlobalState'] === true) {
         $suite->setbeStrictAboutChangesToGlobalState(true);
     }
     if (is_integer($arguments['repeat']) && $arguments['repeat'] > 0) {
         $_suite = new PHPUnit_Framework_TestSuite();
         foreach (range(1, $arguments['repeat']) as $step) {
             $_suite->addTest($suite);
         }
         $suite = $_suite;
         unset($_suite);
     }
     $result = $this->createTestResult();
     if (!$arguments['convertErrorsToExceptions']) {
         $result->convertErrorsToExceptions(false);
     }
     if (!$arguments['convertNoticesToExceptions']) {
         PHPUnit_Framework_Error_Notice::$enabled = false;
     }
     if (!$arguments['convertWarningsToExceptions']) {
         PHPUnit_Framework_Error_Warning::$enabled = false;
     }
     if ($arguments['stopOnError']) {
         $result->stopOnError(true);
     }
     if ($arguments['stopOnFailure']) {
         $result->stopOnFailure(true);
     }
     if ($arguments['stopOnWarning']) {
         $result->stopOnWarning(true);
     }
     if ($arguments['stopOnIncomplete']) {
         $result->stopOnIncomplete(true);
     }
     if ($arguments['stopOnRisky']) {
         $result->stopOnRisky(true);
     }
     if ($arguments['stopOnSkipped']) {
         $result->stopOnSkipped(true);
     }
     if ($arguments['registerMockObjectsFromTestArgumentsRecursively']) {
         $result->setRegisterMockObjectsFromTestArgumentsRecursively(true);
     }
     if ($this->printer === null) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $printerClass = 'PHPUnit_TextUI_ResultPrinter';
             if (isset($arguments['printer']) && is_string($arguments['printer']) && class_exists($arguments['printer'], false)) {
                 $class = new ReflectionClass($arguments['printer']);
                 if ($class->isSubclassOf('PHPUnit_TextUI_ResultPrinter')) {
                     $printerClass = $arguments['printer'];
                 }
             }
             $this->printer = new $printerClass(isset($arguments['stderr']) ? 'php://stderr' : null, $arguments['verbose'], $arguments['colors'], $arguments['debug'], $arguments['columns'], $arguments['reverseList']);
         }
     }
     $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n");
     self::$versionStringPrinted = true;
     if ($arguments['verbose']) {
         $runtime = $this->runtime->getNameWithVersion();
         if ($this->runtime->hasXdebug()) {
             $runtime .= sprintf(' with Xdebug %s', phpversion('xdebug'));
         }
         $this->writeMessage('Runtime', $runtime);
         if (isset($arguments['configuration'])) {
             $this->writeMessage('Configuration', $arguments['configuration']->getFilename());
         }
         foreach ($arguments['loadedExtensions'] as $extension) {
             $this->writeMessage('Extension', $extension);
         }
         foreach ($arguments['notLoadedExtensions'] as $extension) {
             $this->writeMessage('Extension', $extension);
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile'], $arguments['testdoxGroups'], $arguments['testdoxExcludeGroups']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile'], $arguments['testdoxGroups'], $arguments['testdoxExcludeGroups']));
     }
     if (isset($arguments['testdoxXMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_XML($arguments['testdoxXMLFile']));
     }
     $codeCoverageReports = 0;
     if (isset($arguments['coverageClover'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageCrap4J'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageHtml'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coveragePHP'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageText'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageXml'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['noCoverage'])) {
         $codeCoverageReports = 0;
     }
     if ($codeCoverageReports > 0) {
         if (!$this->runtime->canCollectCodeCoverage()) {
             $this->writeMessage('Error', 'No code coverage driver is available');
             $codeCoverageReports = 0;
         } elseif (!isset($arguments['whitelist']) && !$this->codeCoverageFilter->hasWhitelist()) {
             $this->writeMessage('Error', 'No whitelist configured, no code coverage will be generated');
             $codeCoverageReports = 0;
         }
     }
     $this->printer->write("\n");
     if ($codeCoverageReports > 0) {
         $codeCoverage = new CodeCoverage(null, $this->codeCoverageFilter);
         $codeCoverage->setUnintentionallyCoveredSubclassesWhitelist([SebastianBergmann\Comparator\Comparator::class]);
         $codeCoverage->setAddUncoveredFilesFromWhitelist($arguments['addUncoveredFilesFromWhitelist']);
         $codeCoverage->setCheckForUnintentionallyCoveredCode($arguments['strictCoverage']);
         $codeCoverage->setCheckForMissingCoversAnnotation($arguments['strictCoverage']);
         $codeCoverage->setProcessUncoveredFilesFromWhitelist($arguments['processUncoveredFilesFromWhitelist']);
         if (isset($arguments['forceCoversAnnotation'])) {
             $codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
         }
         if (isset($arguments['disableCodeCoverageIgnore'])) {
             $codeCoverage->setDisableIgnoredLines(true);
         }
         if (isset($arguments['whitelist'])) {
             $this->codeCoverageFilter->addDirectoryToWhitelist($arguments['whitelist']);
         }
         $result->setCodeCoverage($codeCoverage);
     }
     if ($codeCoverageReports > 1) {
         if (isset($arguments['cacheTokens'])) {
             $codeCoverage->setCacheTokens($arguments['cacheTokens']);
         }
     }
     if (isset($arguments['teamcityLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TeamCity($arguments['teamcityLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['reportUselessTests']));
     }
     $result->beStrictAboutTestsThatDoNotTestAnything($arguments['reportUselessTests']);
     $result->beStrictAboutOutputDuringTests($arguments['disallowTestOutput']);
     $result->beStrictAboutTodoAnnotatedTests($arguments['disallowTodoAnnotatedTests']);
     $result->beStrictAboutResourceUsageDuringSmallTests($arguments['beStrictAboutResourceUsageDuringSmallTests']);
     $result->enforceTimeLimit($arguments['enforceTimeLimit']);
     $result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
     $result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
     $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
     if ($suite instanceof PHPUnit_Framework_TestSuite) {
         $suite->setRunTestInSeparateProcess($arguments['processIsolation']);
     }
     $suite->run($result);
     unset($suite);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (isset($codeCoverage)) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nGenerating code coverage report in Clover XML format ...");
             try {
                 $writer = new CloverReport();
                 $writer->process($codeCoverage, $arguments['coverageClover']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (CodeCoverageException $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coverageCrap4J'])) {
             $this->printer->write("\nGenerating Crap4J report XML file ...");
             try {
                 $writer = new Crap4jReport($arguments['crap4jThreshold']);
                 $writer->process($codeCoverage, $arguments['coverageCrap4J']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (CodeCoverageException $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coverageHtml'])) {
             $this->printer->write("\nGenerating code coverage report in HTML format ...");
             try {
                 $writer = new HtmlReport($arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], sprintf(' and <a href="https://phpunit.de/">PHPUnit %s</a>', PHPUnit_Runner_Version::id()));
                 $writer->process($codeCoverage, $arguments['coverageHtml']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (CodeCoverageException $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coveragePHP'])) {
             $this->printer->write("\nGenerating code coverage report in PHP format ...");
             try {
                 $writer = new PhpReport();
                 $writer->process($codeCoverage, $arguments['coveragePHP']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (CodeCoverageException $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coverageText'])) {
             if ($arguments['coverageText'] == 'php://stdout') {
                 $outputStream = $this->printer;
                 $colors = $arguments['colors'] && $arguments['colors'] != PHPUnit_TextUI_ResultPrinter::COLOR_NEVER;
             } else {
                 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
                 $colors = false;
             }
             $processor = new TextReport($arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], $arguments['coverageTextShowUncoveredFiles'], $arguments['coverageTextShowOnlySummary']);
             $outputStream->write($processor->process($codeCoverage, $colors));
         }
         if (isset($arguments['coverageXml'])) {
             $this->printer->write("\nGenerating code coverage report in PHPUnit XML format ...");
             try {
                 $writer = new XmlReport();
                 $writer->process($codeCoverage, $arguments['coverageXml']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (CodeCoverageException $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
     }
     if ($exit) {
         if ($result->wasSuccessful()) {
             if ($arguments['failOnRisky'] && !$result->allHarmless()) {
                 exit(self::FAILURE_EXIT);
             }
             if ($arguments['failOnWarning'] && $result->warningCount() > 0) {
                 exit(self::FAILURE_EXIT);
             }
             exit(self::SUCCESS_EXIT);
         }
         if ($result->errorCount() > 0) {
             exit(self::EXCEPTION_EXIT);
         }
         if ($result->failureCount() > 0) {
             exit(self::FAILURE_EXIT);
         }
     }
     return $result;
 }
Beispiel #2
0
 public function testSetForceCoversAnnotation()
 {
     $this->coverage->setForceCoversAnnotation(true);
     $this->assertAttributeEquals(true, 'forceCoversAnnotation', $this->coverage);
 }