Exemple #1
0
 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     if ($this->maxLength == 0) {
         $iterator = new RecursiveIteratorIterator(new PHPUnit_Util_TestSuiteIterator($suite), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($iterator as $item) {
             if ($item instanceof PHPUnit_Framework_TestSuite) {
                 $name = $item->getName();
                 if ($name == '') {
                     $name = '[No name given]';
                 } else {
                     $name = explode('::', $name);
                     $name = array_pop($name);
                 }
                 $this->maxLength = max($this->maxLength, strlen($name));
                 $item->setName($name);
             }
         }
     }
     if ($this->depth > 0) {
         parent::write("\n");
     }
     if ($this->depth == 1) {
         parent::write("\n");
     }
     parent::write(str_pad(str_repeat('  ', $this->depth++) . $suite->getName() . ': ', 40, ' ', STR_PAD_RIGHT));
 }
 public function write($buffer)
 {
     if ($this->capture) {
         $this->buffer .= $buffer;
     } else {
         parent::write($buffer);
     }
 }
 /**
  * @param string $buffer
  * @since  Method available since Release 3.1.0
  */
 protected function write($buffer)
 {
     if (PHP_SAPI != 'cli') {
         $buffer = htmlspecialchars($buffer);
     }
     if ($this->printer !== null) {
         $this->printer->write($buffer);
     } else {
         print $buffer;
     }
 }
Exemple #4
0
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['bootstrap'])) {
         $bootstrap = PHPUnit_Util_Fileloader::load($arguments['bootstrap']);
         if ($bootstrap) {
             $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $bootstrap;
         }
     }
     if ($arguments['backupGlobals'] === FALSE) {
         $suite->setBackupGlobals(FALSE);
     }
     if ($arguments['backupStaticAttributes'] === FALSE) {
         $suite->setBackupStaticAttributes(FALSE);
     }
     $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['stopOnFailure']) {
         $result->stopOnFailure(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP && !self::$versionStringPrinted) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if (isset($arguments['storyHTMLFile'])) {
         require_once 'PHPUnit/Extensions/Story/ResultPrinter/HTML.php';
         $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_HTML($arguments['storyHTMLFile']));
     }
     if (isset($arguments['storyTextFile'])) {
         require_once 'PHPUnit/Extensions/Story/ResultPrinter/Text.php';
         $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_Text($arguments['storyTextFile']));
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         require_once 'PHPUnit/Util/TestDox/ResultPrinter/HTML.php';
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php';
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     if ((isset($arguments['coverageClover']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) {
         $result->collectCodeCoverageInformation(TRUE);
     }
     if (isset($arguments['logDbus'])) {
         require_once 'PHPUnit/Util/Log/DBUS.php';
         $result->addListener(new PHPUnit_Util_Log_DBUS());
     }
     if (isset($arguments['jsonLogfile'])) {
         require_once 'PHPUnit/Util/Log/JSON.php';
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         require_once 'PHPUnit/Util/Log/TAP.php';
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         require_once 'PHPUnit/Util/Log/JUnit.php';
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nWriting code coverage data to XML file, this may take " . 'a moment.');
             require_once 'PHP/CodeCoverage/Report/Clover.php';
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($result->getCodeCoverage(), $arguments['coverageClover']);
             $this->printer->write("\n");
             unset($writer);
         }
         if (isset($arguments['reportDirectory'])) {
             $this->printer->write("\nGenerating code coverage report, this may take a moment.");
             $title = '';
             if (isset($arguments['configuration'])) {
                 $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
                 if (isset($loggingConfiguration['title'])) {
                     $title = $loggingConfiguration['title'];
                 }
             }
             require_once 'PHP/CodeCoverage/Report/HTML.php';
             $writer = new PHP_CodeCoverage_Report_HTML();
             $writer->process($result->getCodeCoverage(), $arguments['reportDirectory'], $title, $arguments['reportCharset'], $arguments['reportYUI'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound']);
             $this->printer->write("\n");
             unset($writer);
         }
     }
     $this->pause($arguments['wait']);
     return $result;
 }
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === FALSE) {
         $suite->setBackupGlobals(FALSE);
     }
     if ($arguments['backupStaticAttributes'] === TRUE) {
         $suite->setBackupStaticAttributes(TRUE);
     }
     if (is_integer($arguments['repeat'])) {
         $suite = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     }
     $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['stopOnIncomplete']) {
         $result->stopOnIncomplete(TRUE);
     }
     if ($arguments['stopOnSkipped']) {
         $result->stopOnSkipped(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP && !self::$versionStringPrinted) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
         if (isset($arguments['configuration'])) {
             $this->printer->write(sprintf("Configuration read from %s\n\n", $arguments['configuration']->getFilename()));
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $result->addListener(new PHPUnit_Util_DeprecatedFeature_Logger());
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     if ((isset($arguments['coverageClover']) || isset($arguments['reportDirectory']) || isset($arguments['coveragePHP']) || isset($arguments['coverageText'])) && extension_loaded('xdebug')) {
         $codeCoverage = new PHP_CodeCoverage(NULL, $this->codeCoverageFilter);
         $codeCoverage->setProcessUncoveredFilesFromWhitelist($arguments['addUncoveredFilesFromWhitelist']);
         if (isset($arguments['cacheTokens'])) {
             $codeCoverage->setCacheTokens($arguments['cacheTokens']);
         }
         if (isset($arguments['forceCoversAnnotation'])) {
             $codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
         }
         if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $codeCoverage->setMapTestClassNameToCoveredClassName($arguments['mapTestClassNameToCoveredClassName']);
         }
         $result->setCodeCoverage($codeCoverage);
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     if ($arguments['strict']) {
         $result->strictMode(TRUE);
         $result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
         $result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
         $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (isset($codeCoverage)) {
         $title = '';
         if (isset($arguments['configuration'])) {
             $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
             if (isset($loggingConfiguration['title'])) {
                 $title = $loggingConfiguration['title'];
             }
         }
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nWriting code coverage data to XML file, this may take " . 'a moment.');
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($codeCoverage, $arguments['coverageClover']);
             $this->printer->write("\n");
             unset($writer);
         }
         if (isset($arguments['reportDirectory'])) {
             $this->printer->write("\nGenerating code coverage report, this may take a moment.");
             $writer = new PHP_CodeCoverage_Report_HTML($title, $arguments['reportCharset'], $arguments['reportYUI'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], ' and PHPUnit ' . PHPUnit_Runner_Version::id());
             $writer->process($codeCoverage, $arguments['reportDirectory']);
             $this->printer->write("\n");
             unset($writer);
         }
         if (isset($arguments['coveragePHP'])) {
             $this->printer->write("\nSerializing PHP_CodeCoverage object to file, this may take a moment.");
             $writer = new PHP_CodeCoverage_Report_PHP();
             $writer->process($codeCoverage, $arguments['coveragePHP']);
             $this->printer->write("\n");
             unset($writer);
         }
         if (isset($arguments['coverageText'])) {
             $this->printer->write("\nGenerating textual code coverage report, this may take a moment.");
             if ($arguments['coverageText'] == 'php://stdout') {
                 $outputStream = $this->printer;
                 $colors = (bool) $arguments['colors'];
             } else {
                 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
                 $colors = FALSE;
             }
             $writer = new PHP_CodeCoverage_Report_Text($outputStream, $title, $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], $arguments['coverageTextShowUncoveredFiles']);
             $writer->process($codeCoverage, $colors);
             $this->printer->write("\n");
         }
     }
     return $result;
 }
Exemple #6
0
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['bootstrap'])) {
         require_once $arguments['bootstrap'];
     }
     if (is_integer($arguments['repeat'])) {
         $suite = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']);
     }
     $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['stopOnFailure']) {
         $result->stopOnFailure(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose'], $arguments['ansi']);
         }
     }
     $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if (isset($arguments['storyHTMLFile'])) {
         require_once 'PHPUnit/Extensions/Story/ResultPrinter/HTML.php';
         $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_HTML($arguments['storyHTMLFile']));
     }
     if (isset($arguments['storyTextFile'])) {
         require_once 'PHPUnit/Extensions/Story/ResultPrinter/Text.php';
         $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_Text($arguments['storyTextFile']));
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         require_once 'PHPUnit/Util/TestDox/ResultPrinter/HTML.php';
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php';
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     if (isset($arguments['graphvizLogfile'])) {
         if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) {
             require_once 'PHPUnit/Util/Log/GraphViz.php';
             $result->addListener(new PHPUnit_Util_Log_GraphViz($arguments['graphvizLogfile']));
         }
     }
     if ((isset($arguments['coverageClover']) || isset($arguments['coverageSource']) || isset($arguments['metricsXML']) || isset($arguments['pmdXML']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) {
         $result->collectCodeCoverageInformation(TRUE);
     }
     if (isset($arguments['jsonLogfile'])) {
         require_once 'PHPUnit/Util/Log/JSON.php';
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         require_once 'PHPUnit/Util/Log/TAP.php';
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['xmlLogfile'])) {
         require_once 'PHPUnit/Util/Log/XML.php';
         $result->addListener(new PHPUnit_Util_Log_XML($arguments['xmlLogfile'], $arguments['logIncompleteSkipped']));
     }
     if (isset($arguments['testDatabaseDSN']) && isset($arguments['testDatabaseLogRevision']) && extension_loaded('pdo')) {
         $writeToTestDatabase = TRUE;
     } else {
         $writeToTestDatabase = FALSE;
     }
     if ($writeToTestDatabase) {
         $dbh = PHPUnit_Util_PDO::factory($arguments['testDatabaseDSN']);
         require_once 'PHPUnit/Util/Log/Database.php';
         $dbListener = PHPUnit_Util_Log_Database::getInstance($dbh, $arguments['testDatabaseLogRevision'], isset($arguments['testDatabaseLogInfo']) ? $arguments['testDatabaseLogInfo'] : '');
         $result->addListener($dbListener);
         $result->collectCodeCoverageInformation(TRUE);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nWriting code coverage data to XML file, this may take a moment.");
             require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Clover.php';
             $writer = new PHPUnit_Util_Log_CodeCoverage_XML_Clover($arguments['coverageClover']);
             $writer->process($result);
             $this->printer->write("\n");
         }
         if (isset($arguments['coverageSource'])) {
             $this->printer->write("\nWriting code coverage data to XML files, this may take a moment.");
             require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Source.php';
             $writer = new PHPUnit_Util_Log_CodeCoverage_XML_Source($arguments['coverageSource']);
             $writer->process($result);
             $this->printer->write("\n");
         }
         if ($writeToTestDatabase) {
             $this->printer->write("\nStoring code coverage and software metrics data in database.\nThis may take a moment.");
             require_once 'PHPUnit/Util/Log/CodeCoverage/Database.php';
             $testDb = new PHPUnit_Util_Log_CodeCoverage_Database($dbh);
             $testDb->storeCodeCoverage($result, $dbListener->getRunId(), $arguments['testDatabaseLogRevision'], $arguments['testDatabasePrefix']);
             $this->printer->write("\n");
         }
         if (isset($arguments['metricsXML'])) {
             $this->printer->write("\nWriting metrics report XML file, this may take a moment.");
             require_once 'PHPUnit/Util/Log/Metrics.php';
             $writer = new PHPUnit_Util_Log_Metrics($arguments['metricsXML']);
             $writer->process($result);
             $this->printer->write("\n");
         }
         if (isset($arguments['pmdXML'])) {
             require_once 'PHPUnit/Util/Log/PMD.php';
             $writer = new PHPUnit_Util_Log_PMD($arguments['pmdXML'], $arguments['pmd']);
             $this->printer->write("\nWriting violations report XML file, this may take a moment.");
             $writer->process($result);
             require_once 'PHPUnit/Util/Log/CPD.php';
             $writer = new PHPUnit_Util_Log_CPD(str_replace('.xml', '-cpd.xml', $arguments['pmdXML']));
             $writer->process($result, $arguments['cpdMinLines'], $arguments['cpdMinMatches']);
             $this->printer->write("\n");
         }
         if (isset($arguments['reportDirectory'])) {
             $this->printer->write("\nGenerating code coverage report, this may take a moment.");
             unset($suite);
             PHPUnit_Util_Report::render($result, $arguments['reportDirectory'], $arguments['reportCharset'], $arguments['reportYUI'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound']);
             $this->printer->write("\n");
         }
     }
     $this->pause($arguments['wait']);
     return $result;
 }
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  *
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === false) {
         $suite->setBackupGlobals(false);
     }
     if ($arguments['backupStaticAttributes'] === true) {
         $suite->setBackupStaticAttributes(true);
     }
     if (is_integer($arguments['repeat'])) {
         $test = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
         $suite = new PHPUnit_Framework_TestSuite();
         $suite->addTest($test);
     }
     $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['stopOnIncomplete']) {
         $result->stopOnIncomplete(true);
     }
     if ($arguments['stopOnSkipped']) {
         $result->stopOnSkipped(true);
     }
     if ($this->printer === null) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(null, $arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
         self::$versionStringPrinted = true;
         if (isset($arguments['configuration'])) {
             $this->printer->write(sprintf("Configuration read from %s\n\n", $arguments['configuration']->getFilename()));
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $result->addListener(new PHPUnit_Util_DeprecatedFeature_Logger());
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     $codeCoverageReports = 0;
     if (extension_loaded('xdebug')) {
         if (isset($arguments['coverageClover'])) {
             $codeCoverageReports++;
         }
         if (isset($arguments['reportDirectory'])) {
             $codeCoverageReports++;
         }
         if (isset($arguments['coveragePHP'])) {
             $codeCoverageReports++;
         }
         if (isset($arguments['coverageText'])) {
             $codeCoverageReports++;
         }
     }
     if ($codeCoverageReports > 0) {
         $codeCoverage = new PHP_CodeCoverage(null, $this->codeCoverageFilter);
         $codeCoverage->setAddUncoveredFilesFromWhitelist($arguments['addUncoveredFilesFromWhitelist']);
         $codeCoverage->setProcessUncoveredFilesFromWhitelist($arguments['processUncoveredFilesFromWhitelist']);
         if (isset($arguments['forceCoversAnnotation'])) {
             $codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
         }
         if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $codeCoverage->setMapTestClassNameToCoveredClassName($arguments['mapTestClassNameToCoveredClassName']);
         }
         $result->setCodeCoverage($codeCoverage);
     }
     if ($codeCoverageReports > 1) {
         if (isset($arguments['cacheTokens'])) {
             $codeCoverage->setCacheTokens($arguments['cacheTokens']);
         }
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     if ($arguments['strict']) {
         $result->strictMode(true);
         $result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
         $result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
         $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     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 ...");
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($codeCoverage, $arguments['coverageClover']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['reportDirectory'])) {
             $this->printer->write("\nGenerating code coverage report in HTML format ...");
             $writer = new PHP_CodeCoverage_Report_HTML($arguments['reportCharset'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], sprintf(' and <a href="http://phpunit.de/">PHPUnit %s</a>', PHPUnit_Runner_Version::id()));
             $writer->process($codeCoverage, $arguments['reportDirectory']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coveragePHP'])) {
             $this->printer->write("\nGenerating code coverage report in PHP format ...");
             $writer = new PHP_CodeCoverage_Report_PHP();
             $writer->process($codeCoverage, $arguments['coveragePHP']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageText'])) {
             if ($arguments['coverageText'] == 'php://stdout') {
                 $outputStream = $this->printer;
                 $colors = (bool) $arguments['colors'];
             } else {
                 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
                 $colors = false;
             }
             $writer = new PHP_CodeCoverage_Report_Text($outputStream, $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], $arguments['coverageTextShowUncoveredFiles']);
             $writer->process($codeCoverage, $colors);
         }
     }
     return $result;
 }
Exemple #8
0
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                   $parameters
  * @return PHPUnit_Framework_TestResult
  * @access public
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $parameters = array())
 {
     $parameters['filter'] = isset($parameters['filter']) ? $parameters['filter'] : FALSE;
     $parameters['stopOnFailure'] = isset($parameters['stopOnFailure']) ? $parameters['stopOnFailure'] : FALSE;
     $parameters['repeat'] = isset($parameters['repeat']) ? $parameters['repeat'] : FALSE;
     $parameters['verbose'] = isset($parameters['verbose']) ? $parameters['verbose'] : FALSE;
     $parameters['wait'] = isset($parameters['wait']) ? $parameters['wait'] : FALSE;
     if (is_integer($parameters['repeat'])) {
         $suite = new PHPUnit_Extensions_RepeatedTest($suite, $parameters['repeat']);
     }
     if (isset($parameters['reportDirectory'])) {
         $parameters['reportDirectory'] = $this->getDirectory($parameters['reportDirectory']);
     }
     $result = $this->createTestResult();
     if ($parameters['stopOnFailure']) {
         $result->stopOnFailure(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($parameters['printer']) && $parameters['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $parameters['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $parameters['verbose']);
         }
     }
     $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
     $result->addListener($this->printer);
     if (isset($parameters['testdoxHTMLFile'])) {
         $result->addListener(PHPUnit_Util_TestDox_ResultPrinter::factory('HTML', $parameters['testdoxHTMLFile']));
     }
     if (isset($parameters['testdoxTextFile'])) {
         $result->addListener(PHPUnit_Util_TestDox_ResultPrinter::factory('Text', $parameters['testdoxTextFile']));
     }
     if (isset($parameters['graphvizLogfile'])) {
         if (class_exists('Image_GraphViz', FALSE)) {
             $result->addListener(new PHPUnit_Util_Log_GraphViz($parameters['graphvizLogfile']));
         }
     }
     if (isset($parameters['reportDirectory']) && extension_loaded('xdebug')) {
         if (class_exists('Image_GraphViz', FALSE)) {
             $result->addListener(new PHPUnit_Util_Report_GraphViz($parameters['reportDirectory']));
         }
         $result->addListener(new PHPUnit_TextUI_ResultPrinter($parameters['reportDirectory'] . '/logfile.txt', TRUE));
         $result->addListener(new PHPUnit_Util_Log_XML($parameters['reportDirectory'] . '/logfile.xml'));
         $result->addListener(new PHPUnit_Util_Log_TAP($parameters['reportDirectory'] . '/logfile.tap'));
         $result->collectCodeCoverageInformation(TRUE);
     }
     if (isset($parameters['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($parameters['jsonLogfile']));
     }
     if (isset($parameters['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($parameters['tapLogfile']));
     }
     if (isset($parameters['xmlLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_XML($parameters['xmlLogfile']));
     }
     if (isset($parameters['testDatabaseDSN']) && isset($parameters['testDatabaseLogRevision']) && extension_loaded('pdo')) {
         $writeToTestDatabase = TRUE;
     } else {
         $writeToTestDatabase = FALSE;
     }
     if ($writeToTestDatabase) {
         $dbh = new PDO($parameters['testDatabaseDSN']);
         $dbListener = PHPUnit_Util_Log_Database::getInstance($dbh, $parameters['testDatabaseLogRevision'], isset($parameters['testDatabaseLogInfo']) ? $parameters['testDatabaseLogInfo'] : '');
         $result->addListener($dbListener);
         $result->collectCodeCoverageInformation(TRUE);
     }
     $suite->run($result, $parameters['filter']);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if ($writeToTestDatabase && extension_loaded('xdebug')) {
         $this->printer->write("\nStoring code coverage data in database, this may take a moment.");
         $testDb = new PHPUnit_Util_Database($dbh);
         $testDb->storeCodeCoverage($result, $parameters['testDatabaseLogRevision']);
         $this->printer->write("\n");
     }
     if (isset($parameters['reportDirectory']) && extension_loaded('xdebug')) {
         $this->printer->write("\nGenerating report, this may take a moment.");
         PHPUnit_Util_Report::render($result, $parameters['reportDirectory']);
         $this->printer->write("\n");
     }
     $this->pause($parameters['wait']);
     return $result;
 }
Exemple #9
0
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === FALSE) {
         $suite->setBackupGlobals(FALSE);
     }
     if ($arguments['backupStaticAttributes'] === TRUE) {
         $suite->setBackupStaticAttributes(TRUE);
     }
     if (is_integer($arguments['repeat'])) {
         $suite = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     }
     $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['stopOnIncomplete']) {
         $result->stopOnIncomplete(TRUE);
     }
     if ($arguments['stopOnSkipped']) {
         $result->stopOnSkipped(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP && !self::$versionStringPrinted) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
         if (isset($arguments['configuration'])) {
             $this->printer->write(sprintf("Configuration read from %s\n\n", $arguments['configuration']->getFilename()));
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $result->addListener(new PHPUnit_Util_DeprecatedFeature_Logger());
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     if ((isset($arguments['coverageClover']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) {
         $result->setCodeCoverage($this->codeCoverage);
     }
     if (isset($arguments['logDbus'])) {
         $result->addListener(new PHPUnit_Util_Log_DBUS());
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     if ($arguments['strict']) {
         $result->strictMode(TRUE);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nWriting code coverage data to XML file, this may take " . 'a moment.');
             $writer = new PHP_CodeCoverage_Report_Clover($arguments['cacheTokens']);
             $writer->process($this->codeCoverage, $arguments['coverageClover']);
             $this->printer->write("\n");
             unset($writer);
         }
         if (isset($arguments['reportDirectory'])) {
             $this->printer->write("\nGenerating code coverage report, this may take a moment.");
             $title = '';
             if (isset($arguments['configuration'])) {
                 $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
                 if (isset($loggingConfiguration['title'])) {
                     $title = $loggingConfiguration['title'];
                 }
             }
             $writer = new PHP_CodeCoverage_Report_HTML(array('title' => $title, 'cacheTokens' => $arguments['cacheTokens'], 'charset' => $arguments['reportCharset'], 'yui' => $arguments['reportYUI'], 'highlight' => $arguments['reportHighlight'], 'lowUpperBound' => $arguments['reportLowUpperBound'], 'highLowerBound' => $arguments['reportHighLowerBound'], 'generator' => ' and PHPUnit ' . PHPUnit_Runner_Version::id()));
             $writer->process($this->codeCoverage, $arguments['reportDirectory']);
             $this->printer->write("\n");
             unset($writer);
         }
     }
     $this->pause($arguments['wait']);
     return $result;
 }
 /**
  * @param  PHPUnit_Framework_Test       $suite
  * @param  array                        $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     $this->processSuiteFilters($suite, $arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === false) {
         $suite->setBackupGlobals(false);
     }
     if ($arguments['backupStaticAttributes'] === true) {
         $suite->setBackupStaticAttributes(true);
     }
     if (is_integer($arguments['repeat'])) {
         $test = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['processIsolation']);
         $suite = new PHPUnit_Framework_TestSuite();
         $suite->addTest($test);
     }
     $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['stopOnIncomplete']) {
         $result->stopOnIncomplete(true);
     }
     if ($arguments['stopOnRisky']) {
         $result->stopOnRisky(true);
     }
     if ($arguments['stopOnSkipped']) {
         $result->stopOnSkipped(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']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
         self::$versionStringPrinted = true;
         if (isset($arguments['configuration'])) {
             $this->printer->write(sprintf("Configuration read from %s\n\n", $arguments['configuration']->getFilename()));
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $result->addListener(new PHPUnit_Util_DeprecatedFeature_Logger());
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     $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 ($codeCoverageReports > 0 && (!extension_loaded('tokenizer') || !$this->canCollectCodeCoverage)) {
         if (!extension_loaded('tokenizer')) {
             $this->showExtensionNotLoadedMessage('tokenizer', 'No code coverage will be generated.');
         } elseif (!extension_loaded('Xdebug')) {
             $this->showExtensionNotLoadedMessage('Xdebug', 'No code coverage will be generated.');
         }
         $codeCoverageReports = 0;
     }
     if ($codeCoverageReports > 0) {
         $codeCoverage = new PHP_CodeCoverage(null, $this->codeCoverageFilter);
         $codeCoverage->setAddUncoveredFilesFromWhitelist($arguments['addUncoveredFilesFromWhitelist']);
         $codeCoverage->setCheckForUnintentionallyCoveredCode($arguments['strictCoverage']);
         $codeCoverage->setProcessUncoveredFilesFromWhitelist($arguments['processUncoveredFilesFromWhitelist']);
         if (isset($arguments['forceCoversAnnotation'])) {
             $codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
         }
         if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $codeCoverage->setMapTestClassNameToCoveredClassName($arguments['mapTestClassNameToCoveredClassName']);
         }
         $result->setCodeCoverage($codeCoverage);
     }
     if ($codeCoverageReports > 1) {
         if (isset($arguments['cacheTokens'])) {
             $codeCoverage->setCacheTokens($arguments['cacheTokens']);
         }
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     $result->beStrictAboutTestsThatDoNotTestAnything($arguments['reportUselessTests']);
     $result->beStrictAboutOutputDuringTests($arguments['disallowTestOutput']);
     $result->beStrictAboutTestSize($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 ...");
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($codeCoverage, $arguments['coverageClover']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageCrap4J'])) {
             $this->printer->write("\nGenerating Crap4J report XML file ...");
             $writer = new PHP_CodeCoverage_Report_Crap4j();
             $writer->process($codeCoverage, $arguments['coverageCrap4J']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageHtml'])) {
             $this->printer->write("\nGenerating code coverage report in HTML format ...");
             $writer = new PHP_CodeCoverage_Report_HTML($arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], sprintf(' and <a href="http://phpunit.de/">PHPUnit %s</a>', PHPUnit_Runner_Version::id()));
             $writer->process($codeCoverage, $arguments['coverageHtml']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coveragePHP'])) {
             $this->printer->write("\nGenerating code coverage report in PHP format ...");
             $writer = new PHP_CodeCoverage_Report_PHP();
             $writer->process($codeCoverage, $arguments['coveragePHP']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageText'])) {
             if ($arguments['coverageText'] == 'php://stdout') {
                 $outputStream = $this->printer;
                 $colors = (bool) $arguments['colors'];
             } else {
                 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
                 $colors = false;
             }
             $processor = new PHP_CodeCoverage_Report_Text($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 ...");
             $writer = new PHP_CodeCoverage_Report_XML();
             $writer->process($codeCoverage, $arguments['coverageXml']);
             $this->printer->write(" done\n");
             unset($writer);
         }
     }
     return $result;
 }
Exemple #11
0
 /**
  * Override this method to automatically remove ansi codes
  */
 public function write($data)
 {
     if (!$this->colors) {
         $data = preg_replace("/\\[[^A-Za-z]*[A-Za-z]/", '', $data);
     }
     parent::write($data);
 }
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  * @return PHPUnit_Framework_TestResult
  * @access public
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (is_integer($arguments['repeat'])) {
         $suite = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']);
     }
     $result = $this->createTestResult();
     if ($arguments['stopOnFailure']) {
         $result->stopOnFailure(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose']);
         }
     }
     $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
     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']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     if (isset($arguments['graphvizLogfile'])) {
         if (class_exists('Image_GraphViz', FALSE)) {
             $result->addListener(new PHPUnit_Util_Log_GraphViz($arguments['graphvizLogfile']));
         }
     }
     if ((isset($arguments['coverageXML']) || isset($arguments['metricsXML']) || isset($arguments['pmdXML'])) && extension_loaded('xdebug')) {
         $result->collectCodeCoverageInformation(TRUE);
     }
     if (isset($arguments['reportDirectory']) && extension_loaded('xdebug')) {
         $result->collectCodeCoverageInformation(TRUE);
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['xmlLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_XML($arguments['xmlLogfile'], $arguments['logIncompleteSkipped']));
     }
     if (isset($arguments['testDatabaseDSN']) && isset($arguments['testDatabaseLogRevision']) && extension_loaded('pdo')) {
         $writeToTestDatabase = TRUE;
     } else {
         $writeToTestDatabase = FALSE;
     }
     if ($writeToTestDatabase) {
         $dbh = PHPUnit_Util_PDO::factory($arguments['testDatabaseDSN']);
         $dbListener = PHPUnit_Util_Log_Database::getInstance($dbh, $arguments['testDatabaseLogRevision'], isset($arguments['testDatabaseLogInfo']) ? $arguments['testDatabaseLogInfo'] : '');
         $result->addListener($dbListener);
         $result->collectCodeCoverageInformation(TRUE);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (isset($arguments['coverageXML']) && extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         $this->printer->write("\nWriting code coverage data to XML file, this may take a moment.");
         $writer = new PHPUnit_Util_Log_CodeCoverage_XML($arguments['coverageXML']);
         $writer->process($result);
         $this->printer->write("\n");
     }
     if ($writeToTestDatabase && extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         $this->printer->write("\nStoring code coverage and software metrics data in database.\nThis may take a moment.");
         $testDb = new PHPUnit_Util_Log_CodeCoverage_Database($dbh);
         $testDb->storeCodeCoverage($result, $dbListener->getRunId(), $arguments['testDatabaseLogRevision'], $arguments['testDatabasePrefix']);
         $this->printer->write("\n");
     }
     if (isset($arguments['metricsXML']) && extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         $this->printer->write("\nWriting metrics report XML file, this may take a moment.");
         $writer = new PHPUnit_Util_Log_Metrics($arguments['metricsXML']);
         $writer->process($result);
         $this->printer->write("\n");
     }
     if (isset($arguments['pmdXML']) && extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         $writer = new PHPUnit_Util_Log_PMD($arguments['pmdXML'], $arguments['pmd']);
         $this->printer->write("\nWriting violations report XML file, this may take a moment.");
         $writer->process($result);
         $writer = new PHPUnit_Util_Log_CPD(str_replace('.xml', '-cpd.xml', $arguments['pmdXML']));
         $writer->process($result, $arguments['cpdMinLines'], $arguments['cpdMinMatches']);
         $this->printer->write("\n");
     }
     if (isset($arguments['reportDirectory']) && extension_loaded('xdebug')) {
         $this->printer->write("\nGenerating code coverage report, this may take a moment.");
         PHPUnit_Util_Report::render($result, $arguments['reportDirectory'], $arguments['reportCharset'], $arguments['reportYUI'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound']);
         $this->printer->write("\n");
     }
     $this->pause($arguments['wait']);
     return $result;
 }