Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function printStep(Formatter $formatter, Scenario $scenario, StepNode $step, StepResult $result)
 {
     $this->printText($formatter->getOutputPrinter(), $step->getKeyword(), $step->getText(), $result);
     $this->pathPrinter->printStepPath($formatter, $scenario, $step, $result, mb_strlen($this->indentText, 'utf8'));
     $this->printArguments($formatter, $step->getArguments(), $result);
     $this->printStdOut($formatter->getOutputPrinter(), $result);
     $this->printException($formatter->getOutputPrinter(), $result);
 }
Пример #2
0
 /**
  * Prints step using provided printer.
  *
  * @param Formatter  $formatter
  * @param Scenario   $scenario
  * @param StepNode   $step
  * @param StepResult $result
  */
 public function printStep(Formatter $formatter, Scenario $scenario, StepNode $step, StepResult $result)
 {
     /** @var JUnitOutputPrinter $outputPrinter */
     $outputPrinter = $formatter->getOutputPrinter();
     $message = $step->getKeyword() . ' ' . $step->getText();
     if ($result instanceof ExceptionResult && $result->hasException()) {
         $message .= ': ' . $this->exceptionPresenter->presentException($result->getException());
     }
     $attributes = array('message' => $message);
     switch ($result->getResultCode()) {
         case TestResult::FAILED:
             $outputPrinter->addTestcaseChild('failure', $attributes);
             break;
         case TestResult::PENDING:
             $attributes['type'] = 'pending';
             $outputPrinter->addTestcaseChild('error', $attributes);
             break;
         case StepResult::UNDEFINED:
             $attributes['type'] = 'undefined';
             $outputPrinter->addTestcaseChild('error', $attributes);
             break;
     }
 }
Пример #3
0
 protected function runStep(StepNode $stepNode)
 {
     $params = [];
     if ($stepNode->hasArguments()) {
         $args = $stepNode->getArguments();
         $table = $args[0];
         if ($table instanceof TableNode) {
             $params = [$table->getTableAsString()];
         }
     }
     $meta = new Meta($stepNode->getText(), $params);
     $meta->setPrefix($stepNode->getKeyword());
     $this->scenario->setMetaStep($meta);
     // enable metastep
     $stepText = $stepNode->getText();
     $this->getScenario()->comment(null);
     // make metastep to be printed even if no steps
     foreach ($this->steps as $pattern => $context) {
         $matches = [];
         if (!preg_match($pattern, $stepText, $matches)) {
             continue;
         }
         array_shift($matches);
         if ($stepNode->hasArguments()) {
             $matches = array_merge($matches, $stepNode->getArguments());
         }
         call_user_func_array($context, $matches);
         // execute the step
         break;
     }
     $this->scenario->setMetaStep(null);
     // disable metastep
 }
Пример #4
0
 /**
  * Changes step node type for types But, And to type of previous step if it exists else sets to Given
  *
  * @param StepNode   $node
  * @param StepNode[] $steps
  * @return StepNode
  */
 private function normalizeStepNodeKeywordType(StepNode $node, array $steps = array())
 {
     if (in_array($node->getKeywordType(), array('And', 'But'))) {
         if ($prev = end($steps)) {
             $keywordType = $prev->getKeywordType();
         } else {
             $keywordType = 'Given';
         }
         $node = new StepNode($node->getKeyword(), $node->getText(), $node->getArguments(), $node->getLine(), $keywordType);
     }
     return $node;
 }
Пример #5
0
 /**
  * @param StepNode $step
  *
  * @return string
  */
 private function getStepText(StepNode $step)
 {
     $spacesQuantity = $this->computeIndentationSpaces($step->getKeyword());
     return rtrim(sprintf('%s%s %s', $this->indent($spacesQuantity + self::INDENTATION), trim($step->getKeyword()), trim($step->getText()))) . "\n";
 }
Пример #6
0
 /**
  * Calculates step width.
  *
  * @param StepNode $step
  * @param integer  $indentation
  *
  * @return integer
  */
 public function calculateStepWidth(StepNode $step, $indentation)
 {
     $indentText = str_repeat(' ', intval($indentation));
     $text = sprintf('%s%s %s', $indentText, $step->getKeyword(), $step->getText());
     return mb_strlen($text, 'utf8');
 }