Ejemplo n.º 1
0
 /**
  * @param \PHPUnit_Framework_TestResult $result
  */
 public function printResult(\PHPUnit_Framework_TestResult $result)
 {
     if ($this->runner->shouldNotify()) {
         ob_start();
     }
     $testDox = trim(TestDox::get(spl_object_hash($result)));
     if (strlen($testDox)) {
         $this->write(PHP_EOL . PHP_EOL . $testDox);
     }
     parent::printResult($result);
     if ($this->runner->shouldNotify()) {
         $output = ob_get_contents();
         ob_end_clean();
         echo $output;
         if ($result->failureCount() + $result->errorCount() + $result->skippedCount() + $result->notImplementedCount() == 0) {
             $notificationResult = Notification::RESULT_PASSED;
         } else {
             $notificationResult = Notification::RESULT_FAILED;
         }
         if (preg_match('/^(?:\\x1b\\[30;42m\\x1b\\[2K)?(OK .+)/m', $output, $matches)) {
             $notificationMessage = $matches[1];
         } elseif (preg_match('/^(?:\\x1b\\[37;41m\\x1b\\[2K)?(FAILURES!)\\s^(?:\\x1b\\[0m\\x1b\\[37;41m\\x1b\\[2K)?(.+)/m', $output, $matches)) {
             $notificationMessage = $matches[1] . PHP_EOL . $matches[2];
         } elseif (preg_match('/^(?:\\x1b\\[30;43m\\x1b\\[2K)?(OK, but incomplete or skipped tests!)\\s^(?:\\x1b\\[0m\\x1b\\[30;43m\\x1b\\[2K)?(.+)/m', $output, $matches)) {
             $notificationMessage = $matches[1] . PHP_EOL . $matches[2];
         } elseif (preg_match('/^(?:\\x1b\\[30;43m\\x1b\\[2K)?(No tests executed!)/m', $output, $matches)) {
             $notificationMessage = $matches[1];
         }
         $this->notification = new Notification($notificationResult, $notificationMessage);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param \PHPUnit_Framework_TestResult $result
  */
 public function printResult(\PHPUnit_Framework_TestResult $result)
 {
     if ($this->runner->shouldNotify()) {
         ob_start();
     }
     $testDox = trim(TestDox::get(spl_object_hash($result)));
     if (strlen($testDox)) {
         $this->write(PHP_EOL . PHP_EOL . $testDox);
     }
     parent::printResult($result);
     if ($this->runner->shouldNotify()) {
         $output = ob_get_contents();
         ob_end_clean();
         echo $output;
         if ($result->failureCount() + $result->errorCount() + $result->skippedCount() + $result->notImplementedCount() == 0) {
             $notificationResult = Notification::RESULT_PASSED;
         } else {
             $notificationResult = Notification::RESULT_FAILED;
         }
         $output = $this->removeAnsiEscapeCodesForColors($output);
         if (preg_match('/(OK \\(\\d+ tests?, \\d+ assertions?\\))/', $output, $matches)) {
             $notificationMessage = $matches[1];
         } elseif (preg_match('/(FAILURES!)\\s+(.*)/', $output, $matches)) {
             $notificationMessage = $matches[1] . PHP_EOL . $matches[2];
         } elseif (preg_match('/(OK, but incomplete,.*!)\\s+(.*)/', $output, $matches)) {
             $notificationMessage = $matches[1] . PHP_EOL . $matches[2];
         } elseif (preg_match('/(No tests executed!)/', $output, $matches)) {
             $notificationMessage = $matches[1];
         } else {
             $notificationMessage = '';
         }
         $this->notification = new Notification($notificationResult, $notificationMessage);
     }
 }
Ejemplo n.º 3
0
 /**
  * Runs tests.
  *
  * @since Method available since Release 2.1.0
  */
 public function run()
 {
     $this->outputBuffering->clearOutputHandlers();
     $this->result = $this->runner->run($this->collector->collect());
     if ($this->runner->shouldNotify()) {
         $this->notifier->notifyResult($this->runner->getNotification());
     }
 }
Ejemplo n.º 4
0
 /**
  * Runs tests.
  *
  * @since Method available since Release 2.1.0
  */
 public function run()
 {
     $this->outputBuffering->clearOutputHandlers();
     $this->runner->run($this->collector->collect());
     if ($this->runner->shouldNotify()) {
         $notification = $this->runner->getNotification();
         if (is_null($notification)) {
             throw new \LogicException('The Notification object is not set to the Runner object.');
         }
         $this->notifyResult($notification);
     }
 }
Ejemplo n.º 5
0
 public function paintFooter($test_name)
 {
     ob_start();
     parent::paintFooter($test_name);
     $output = ob_get_contents();
     ob_end_clean();
     if ($this->terminal->shouldColor()) {
         if ($this->getFailCount() + $this->getExceptionCount() == 0) {
             echo Coloring::green($output);
         } else {
             echo Coloring::red($output);
         }
     } else {
         echo $output;
     }
     if ($this->runner->shouldNotify()) {
         if ($this->getFailCount() + $this->getExceptionCount() == 0) {
             $notificationResult = Notification::RESULT_PASSED;
         } else {
             $notificationResult = Notification::RESULT_FAILED;
         }
         $this->notification = new Notification($notificationResult, $output);
     }
 }
 /**
  * @param string $command
  *
  * @return array
  */
 protected function buildOptions($command)
 {
     $options = array();
     if (basename(trim($command, '\'"')) != 'testrunner') {
         $configFile = $this->getPHPConfigDir();
         if ($configFile !== false) {
             $options[] = '-c';
             $options[] = escapeshellarg($configFile);
         }
         $options[] = escapeshellarg($_SERVER['argv'][0]);
     }
     if ($this->terminal->shouldColor()) {
         $options[] = '--ansi';
     }
     $options[] = escapeshellarg(strtolower($this->plugin->getPluginID()));
     if (!is_null($this->environment->getPreloadScript())) {
         $options[] = '-p ' . escapeshellarg($this->environment->getPreloadScript());
     }
     $options[] = '-R';
     if ($this->runner->shouldNotify()) {
         $options[] = '-m';
     }
     if ($this->runner->shouldStopOnFailure()) {
         $options[] = '--stop-on-failure';
     }
     if (!$this->testTargetRepository->isDefaultFilePattern()) {
         $options[] = '--test-file-pattern=' . escapeshellarg($this->testTargetRepository->getFilePattern());
     }
     if ($this->runner->hasDetailedProgress()) {
         $options[] = '--detailed-progress';
     }
     if (!is_null($this->commandLineOptionBuilder)) {
         $options = $this->commandLineOptionBuilder->build($options);
     }
     $this->testTargetRepository->walkOnResources(function ($resource, $index, TestTargetRepository $testTargetRepository) use(&$options) {
         $options[] = escapeshellarg($resource);
     });
     return $options;
 }
 /**
  * @param string $commandLine
  * @since Method available since Release 2.18.0
  */
 public function runTests($commandLine)
 {
     $streamOutput = '';
     if ($this->os->isWin()) {
         // TODO: Remove Windows specific code if the bug #60120 and #51800 are really fixed.
         ob_start(function ($buffer) use(&$streamOutput) {
             $streamOutput .= $buffer;
             return $buffer;
         }, 2);
         passthru($commandLine, $exitStatus);
         ob_end_flush();
     } else {
         $process = new Process($commandLine);
         $process->setTimeout(60);
         $exitStatus = $process->run(function ($type, $data) {
             echo $data;
         });
         $streamOutput = $process->getOutput();
     }
     if ($exitStatus != 0 && $this->runner->shouldNotify()) {
         $fatalError = new FatalError($streamOutput);
         $this->notifier->notifyResult(new Notification(Notification::RESULT_STOPPED, $fatalError->getFullMessage()));
     }
 }