Ejemplo n.º 1
0
 function its_runAll_create_success_event_if_results_only_contain_success_events(Runner $runner)
 {
     $results = array('succeed1' => ResultEvent::createSucceed('Succeed1'), 'succeed2' => ResultEvent::createSucceed('Succeed2'), 'succeed3' => ResultEvent::createSucceed('Succeed3'));
     Filesystem::create()->serialize($this->cacheFile, $results);
     $runner->run(Argument::any())->shouldBeCalled();
     $results = $this->runAll()->getResults();
     $results->shouldHaveCount(1);
     $result = $results[0];
     $result->shouldBeSucceed();
 }
Ejemplo n.º 2
0
 /**
  * @param mixed $event
  */
 public function __construct($event)
 {
     $map = array(StepEvent::PASSED => static::SUCCEED, StepEvent::FAILED => static::FAILED, StepEvent::PENDING => static::FAILED, StepEvent::SKIPPED => static::SUCCEED, StepEvent::UNDEFINED => static::BROKEN);
     $result = static::BROKEN;
     if (array_key_exists($event->getResult(), $map)) {
         $result = $map[$event->getResult()];
     }
     $message = 'Unknown Result';
     if ($event instanceof ScenarioEvent) {
         $message = $this->buildScenarioEvent($event);
     } elseif ($event instanceof FeatureEvent) {
         $message = $this->buildFeatureEvent($event);
     } elseif ($event instanceof StepEvent) {
         $message = $this->buildStepEvent($event);
     }
     $this->key = md5($this->file . $this->line);
     parent::__construct($result, $message);
 }
Ejemplo n.º 3
0
 function its_runAll_should_set_application_exit_code_if_results_has_failed_or_broken(ContainerInterface $container)
 {
     $failed = ResultEvent::createFailed('Failed', array('file' => 'some_file'));
     $success = ResultEvent::createSucceed('Success');
     Filesystem::create()->serialize($this->cacheFile, array('failed' => $failed, 'success' => $success));
     $container->setParameter('application.exit_code', ResultEvent::FAILED)->shouldBeCalled();
     $this->runAll();
 }
Ejemplo n.º 4
0
 /**
  * @codeCoverageIgnore
  */
 public function handleShutdown()
 {
     $fatalErrors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR);
     $lastError = error_get_last();
     if ($lastError && in_array($lastError['type'], $fatalErrors)) {
         $message = 'Fatal Error ' . $lastError['message'];
         $error = $lastError;
         $trace = file($this->errorFile);
         $traces = array();
         for ($i = 0, $count = count($trace); $i < $count; $i++) {
             $text = trim($trace[$i]);
             if (false !== ($pos = strpos($text, 'PHP '))) {
                 $text = substr($text, $pos + 4);
             }
             $traces[] = $text;
         }
         $event = ResultEvent::createError($message, $error, null, $traces);
         Filesystem::create()->serialize(Inspector::getResultFileName(), array($event));
         if ($this->coverageRunner) {
             $this->coverageRunner->saveState();
         }
     }
 }
Ejemplo n.º 5
0
 private function doRunAll()
 {
     $command = $this->cmdRunAll;
     if ($this->options['keep_failed']) {
         $files = array();
         foreach ($this->failed as $key => $failedEvent) {
             $file = $failedEvent->getArgument('file');
             if (file_exists($file)) {
                 $file = ltrim(str_replace(getcwd(), '', $file), '\\/');
                 if (!in_array($file, $files)) {
                     $files[] = $file;
                 }
             }
         }
         $files = array_unique($files);
         if (!empty($files)) {
             $command = $this->cmdRun;
             $specFiles = implode(',', $files);
             $command = $command . ' --spec-files=' . $specFiles;
             $this->logger->debug('Keep failed spec run');
         }
     }
     // start to run phpspec command
     $arguments = explode(' ', $command);
     $builder = new ProcessBuilder($arguments);
     $runner = $this->getRunner();
     $runner->run($builder);
     // not showing success events for run all
     $results = $this->renderResult(false);
     if (count($this->failed) === 0) {
         $results[] = ResultEvent::createSucceed('Run all specs success');
     }
     return $results;
 }
Ejemplo n.º 6
0
 /**
  * @return ResultEvent[]
  */
 private function doRunAll()
 {
     $results = array();
     $arguments = $this->runAllArgs;
     $this->session = Session::create();
     if ($this->isFailed()) {
         $rerunFile = $this->session->generateRerunFile();
         $arguments[] = '--rerun=' . $rerunFile;
     }
     $builder = new ProcessBuilder($arguments);
     $this->getRunner()->run($builder);
     $this->session = Session::create();
     if (!$this->isFailed()) {
         $results[] = ResultEvent::createSucceed(static::RUN_ALL_SUCCESS_MESSAGE);
     } else {
         $results = $this->session->getResults();
         $results[] = ResultEvent::createFailed(static::RUN_ALL_FAILED_MESSAGE);
     }
     return $results;
 }
Ejemplo n.º 7
0
 private function doRunAll()
 {
     $args = $this->runAllCli;
     $args = explode(' ', $args);
     if (count($this->failed) > 0) {
         $files = array();
         foreach ($this->failed as $file) {
             //$file=$resultEvent->getArgument('file');
             $file = ltrim(str_replace(getcwd(), '', $file), '\\/');
             $files[] = $file;
         }
         if (!empty($files)) {
             $this->getLogger()->addDebug('keep failed tests run');
             $files = array_unique($files);
             $args[] = implode(',', $files);
         }
     }
     $builder = new ProcessBuilder($args);
     $builder->setPrefix($this->executable);
     $runner = $this->getRunner();
     $runner->run($builder);
     $results = $this->checkResult(false);
     if (0 === count($this->failed)) {
         $results['all_after_pass'] = ResultEvent::createSucceed(static::MSG_RUN_ALL_SUCCESS);
     }
     return $results;
 }
Ejemplo n.º 8
0
 private function addResult($result, SpecificationNode $spec, $title = null)
 {
     $map = array(ResultEvent::SUCCEED => 'Succeed: %title%', ResultEvent::FAILED => 'Failed: %title%', ResultEvent::BROKEN => 'Broken: %title%', ResultEvent::ERROR => 'Error: %title%');
     $r = $spec->getClassReflection();
     $arguments = array('file' => $r->getFileName());
     $key = md5($r->getFileName() . $title);
     $format = $map[$result];
     $title = $title == null ? $spec->getTitle() : $spec->getTitle() . '::' . $title;
     $message = strtr($format, array('%title%' => '<highlight>' . $title . '</highlight>'));
     $this->results[$key] = ResultEvent::create($result, $message, $arguments);
 }