Author: Sebastian Bergmann (sebastian@phpunit.de)
Inheritance: extends PHPUnit_Util_Printer, implements PHPUnit_Framework_TestListener
 /**
  * @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['repeat'] = isset($parameters['repeat']) ? $parameters['repeat'] : FALSE;
     $parameters['filter'] = isset($parameters['filter']) ? $parameters['filter'] : FALSE;
     $parameters['verbose'] = isset($parameters['verbose']) ? $parameters['verbose'] : 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 ($this->printer === NULL) {
         $this->printer = $parameters['xml'] ? new CopixTestXMLPrinter(NULL, $parameters['verbose']) : new CopixTestPrinter(NULL, $parameters['verbose']);
     }
     $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) && class_exists('PHPUnit_Util_Log_GraphViz', FALSE)) {
             $result->addListener(new PHPUnit_Util_Log_GraphViz($parameters['graphvizLogfile']));
         }
     }
     if (isset($parameters['reportDirectory']) && extension_loaded('xdebug')) {
         if (class_exists('Image_GraphViz', FALSE) && class_exists('PHPUnit_Util_Report_GraphViz', FALSE)) {
             $result->addListener(new PHPUnit_Util_Report_GraphViz($parameters['reportDirectory']));
         }
         $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']));
     }
     $suite->run($result, $parameters['filter']);
     $result->flushListeners();
     if (isset($parameters['reportDirectory']) && extension_loaded('xdebug')) {
         $this->printer->codeCoverage($parameters['reportDirectory']);
         PHPUnit_Util_Report::render($result, $parameters['reportDirectory']);
     } else {
         $this->printer->codeCoverage(false);
     }
     if ($this->printer) {
         $this->printer->printResult($result);
     }
     return $result;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * @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(PHPUnit_Util_TestDox_ResultPrinter::factory('HTML', $arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(PHPUnit_Util_TestDox_ResultPrinter::factory('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;
 }