Exemple #1
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
  * @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;
 }