run() public method

Runs single test.
public run ( $flags = NULL ) : void
return void
Esempio n. 1
0
 /** @return int|NULL */
 public function run()
 {
     Environment::setupColors();
     Environment::setupErrors();
     ob_start();
     $cmd = $this->loadOptions();
     Environment::$debugMode = (bool) $this->options['--debug'];
     if (isset($this->options['--colors'])) {
         Environment::$useColors = (bool) $this->options['--colors'];
     } elseif (in_array($this->options['-o'], ['tap', 'junit'])) {
         Environment::$useColors = FALSE;
     }
     if ($cmd->isEmpty() || $this->options['--help']) {
         $cmd->help();
         return;
     }
     $this->createPhpInterpreter();
     if ($this->options['--info']) {
         $job = new Job(__DIR__ . '/info.php', $this->interpreter);
         $job->run();
         echo $job->getOutput();
         return;
     }
     if ($this->options['--coverage']) {
         $coverageFile = $this->prepareCodeCoverage();
     }
     $runner = $this->createRunner();
     $runner->setEnvironmentVariable(Environment::RUNNER, 1);
     $runner->setEnvironmentVariable(Environment::COLORS, (int) Environment::$useColors);
     if (isset($coverageFile)) {
         $runner->setEnvironmentVariable(Environment::COVERAGE, $coverageFile);
     }
     if ($this->options['-o'] !== NULL) {
         ob_clean();
     }
     ob_end_flush();
     if ($this->options['--watch']) {
         $this->watch($runner);
         return;
     }
     $result = $runner->run();
     if (isset($coverageFile) && preg_match('#\\.(?:html?|xml)\\z#', $coverageFile)) {
         $this->finishCodeCoverage($coverageFile);
     }
     return $result ? 0 : 1;
 }
 public function __construct($path, $args = NULL)
 {
     $this->path = Helpers::escapeArg($path);
     $proc = proc_open("{$this->path} -n {$args} -v", array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     $output = stream_get_contents($pipes[1]);
     $this->error = trim(stream_get_contents($pipes[2]));
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$path}': " . preg_replace('#[\\r\\n ]+#', ' ', $this->error));
     } elseif (!preg_match('#^PHP (\\S+).*c(g|l)i#i', $output, $matches)) {
         throw new \Exception("Unable to detect PHP version (output: {$output}).");
     }
     $this->version = $matches[1];
     $this->cgi = strcasecmp($matches[2], 'g') === 0;
     $this->arguments = $args;
     $job = new Job(__DIR__ . '/info.php', $this, array('xdebug'));
     $job->run();
     $this->xdebug = !$job->getExitCode();
 }
Esempio n. 3
0
 /** @return int|NULL */
 public function run()
 {
     Environment::setupColors();
     Environment::setupErrors();
     ob_start();
     $cmd = $this->loadOptions();
     Environment::$debugMode = (bool) $this->options['--debug'];
     if (isset($this->options['--colors'])) {
         Environment::$useColors = (bool) $this->options['--colors'];
     } elseif ($this->options['-o'] === 'tap') {
         Environment::$useColors = FALSE;
     }
     if ($cmd->isEmpty() || $this->options['--help']) {
         $cmd->help();
         return;
     }
     $this->createPhpInterpreter();
     if ($this->options['--info']) {
         $job = new Job(__DIR__ . '/info.php', $this->interpreter);
         $job->run();
         echo $job->getOutput();
         return;
     }
     if ($this->options['--coverage']) {
         $coverageFile = $this->prepareCodeCoverage();
     }
     $runner = $this->createRunner();
     if ($this->options['-o'] !== NULL) {
         ob_clean();
     }
     ob_end_flush();
     if ($this->options['--watch']) {
         $this->watch($runner);
         return;
     }
     $result = $runner->run();
     if (isset($coverageFile)) {
         $this->finishCodeCoverage($coverageFile);
     }
     return $result ? 0 : 1;
 }
Esempio n. 4
0
 private function initiateTestCase($foo, PhpExecutable $php, $file)
 {
     $job = new Job($file, $php, Helpers::escapeArg(Tester\TestCase::LIST_METHODS));
     $job->run();
     if (in_array($job->getExitCode(), array(Job::CODE_ERROR, Job::CODE_FAIL, Job::CODE_SKIP))) {
         return array($job->getExitCode() === Job::CODE_SKIP ? Runner::SKIPPED : Runner::FAILED, $job->getOutput());
     }
     $methods = json_decode(strrchr($job->getOutput(), '['));
     if (!is_array($methods)) {
         return array(Runner::FAILED, "Cannot list TestCase methods in file '{$file}'. Do you call TestCase::run() in it?");
     } elseif (!$methods) {
         return array(Runner::SKIPPED, "TestCase in file '{$file}' does not contain test methods.");
     }
     foreach ($methods as $method) {
         $this->runner->addJob(new Job($file, $php, Helpers::escapeArg($method)));
     }
     return TRUE;
 }
Esempio n. 5
0
 private function initiateTestCase($foo, PhpInterpreter $interpreter, $file)
 {
     $job = new Job($file, $interpreter, array(Helpers::escapeArg('--method=' . Tester\TestCase::LIST_METHODS)));
     $job->run();
     if (in_array($job->getExitCode(), array(Job::CODE_ERROR, Job::CODE_FAIL, Job::CODE_SKIP), TRUE)) {
         return array($job->getExitCode() === Job::CODE_SKIP ? Runner::SKIPPED : Runner::FAILED, $job->getOutput());
     }
     if (!preg_match('#\\[([^[]*)]#', strrchr($job->getOutput(), '['), $m)) {
         return array(Runner::FAILED, "Cannot list TestCase methods in file '{$file}'. Do you call TestCase::run() in it?");
     } elseif (!strlen($m[1])) {
         return array(Runner::SKIPPED, "TestCase in file '{$file}' does not contain test methods.");
     }
     return array('method', explode(',', $m[1]));
 }