/**
  * @param boolean $specs
  */
 public function output($specs = false)
 {
     $output = preg_replace(array('/(\\x0d|\\x0a|\\x0d\\x0a){3,}/', '/^(  -)(.+)/m'), array("\n\n", '$1 $2'), $this->toString($specs));
     if ($this->color) {
         $failuresCount = $this->_result->countFailures();
         $deliberateFailuresCount = $this->_result->countDeliberateFailures();
         $errorsCount = $this->_result->countErrors();
         $exceptionsCount = $this->_result->countExceptions();
         $pendingsCount = $this->_result->countPending();
         if ($failuresCount + $deliberateFailuresCount + $errorsCount + $exceptionsCount + $pendingsCount == 0) {
             $colorLabel = 'green';
         } elseif ($pendingsCount && $failuresCount + $deliberateFailuresCount + $errorsCount + $exceptionsCount == 0) {
             $colorLabel = 'yellow';
         } else {
             $colorLabel = 'red';
         }
         $oldErrorReportingLevel = error_reporting(error_reporting() & ~E_STRICT);
         $output = preg_replace(array('/^(\\d+ examples?.*)/m', '/^(  -)(.+)( \\(ERROR|EXCEPTION\\))/m', '/^(  -)(.+)( \\(FAIL\\))/m', '/^(  -)(.+)( \\(DELIBERATEFAIL\\))/m', '/^(  -)(.+)( \\(PENDING\\))/m', '/^(  -)(.+)/m', '/(\\d+\\)\\s+)(.+ (?:ERROR|EXCEPTION)\\s+.+)/', '/(\\d+\\)\\s+)(.+ FAILED\\s+.+)/', '/(\\d+\\)\\s+)(.+ PENDING\\s+.+)/', '/^((?:Errors|Exceptions):)/m', '/^(Failures:)/m', '/^(Pending:)/m'), array(Stagehand_TestRunner_Coloring::$colorLabel('$1'), Stagehand_TestRunner_Coloring::magenta('$1$2$3'), Stagehand_TestRunner_Coloring::red('$1$2$3'), Stagehand_TestRunner_Coloring::red('$1$2$3'), Stagehand_TestRunner_Coloring::yellow('$1$2$3'), Stagehand_TestRunner_Coloring::green('$1$2$3'), '$1' . Stagehand_TestRunner_Coloring::magenta('$2'), '$1' . Stagehand_TestRunner_Coloring::red('$2'), '$1' . Stagehand_TestRunner_Coloring::yellow('$2'), Stagehand_TestRunner_Coloring::magenta('$1'), Stagehand_TestRunner_Coloring::red('$1'), Stagehand_TestRunner_Coloring::yellow('$1')), Console_Color::escape($output));
         error_reporting($oldErrorReportingLevel);
     }
     print $output;
 }
示例#2
0
 /**
  * Runs tests based on the given TestSuite object.
  *
  * @param TestSuite $suite
  */
 public function run($suite)
 {
     $reporter = new MultipleReporter();
     $reporter->attachReporter($this->decorateReporter(new TextReporter()));
     if ($this->config->logsResultsInJUnitXML) {
         if (!$this->config->logsResultsInJUnitXMLInRealtime) {
             $xmlWriter = new Stagehand_TestRunner_JUnitXMLWriter_JUnitXMLDOMWriter(array($this, 'writeJUnitXMLToFile'));
         } else {
             $xmlWriter = $this->junitXMLStreamWriter(array($this, 'writeJUnitXMLToFile'));
         }
         $junitXMLReporter = new $this->junitXMLReporterClass($this->config);
         $junitXMLReporter->setXMLWriter($xmlWriter);
         $junitXMLReporter->setTestSuite($suite);
         $junitXMLReporter->setConfig($this->config);
         $reporter->attachReporter($this->decorateReporter($junitXMLReporter));
     }
     ob_start();
     $suite->run($reporter);
     $output = ob_get_contents();
     ob_end_clean();
     if ($this->config->logsResultsInJUnitXML) {
         if (is_resource($this->junitXMLFileHandle)) {
             fclose($this->junitXMLFileHandle);
         }
     }
     if ($this->config->usesGrowl) {
         if (preg_match('/^(OK.+)/ms', $output, $matches)) {
             $this->notification->name = 'Green';
             $this->notification->description = $matches[1];
         } elseif (preg_match('/^(FAILURES.+)/ms', $output, $matches)) {
             $this->notification->name = 'Red';
             $this->notification->description = $matches[1];
         }
     }
     if ($this->config->colors) {
         print Console_Color::convert(preg_replace(array('/^(OK.+)/ms', '/^(FAILURES!!!.+)/ms', '/^(\\d+\\)\\s)(.+at \\[.+\\]$\\s+in .+)$/m', '/^(Exception \\d+!)/m', '/^(Unexpected exception of type \\[.+\\] with message \\[.+\\] in \\[.+\\]$\\s+in .+)$/m'), array('%g$1%n', '%r$1%n', "\$1%r\$2%n", '%p$1%n', '%p$1%n'), Console_Color::escape($output)));
     } else {
         print $output;
     }
 }