예제 #1
0
 public function testType()
 {
     $step = new StepNode('When');
     $this->assertEquals('When', $step->getType());
     $step->setType('Given');
     $this->assertEquals('Given', $step->getType());
 }
예제 #2
0
 /**
  * Initializes definition snippet.
  *
  * @param   Behat\Gherkin\Node\StepNode $step       step interested in snippet
  * @param   string                      $template   definition snippet template
  */
 public function __construct(StepNode $step, $template)
 {
     $type = $step->getType();
     $this->type = in_array($type, array('Given', 'When', 'Then')) ? $type : 'Given';
     $this->template = $template;
     $this->steps[] = $step;
 }
예제 #3
0
 /**
  * Prints step definition path.
  *
  * @param StepNode            $step       step node
  * @param DefinitionInterface $definition definition (if found one)
  *
  * @uses printPathComment()
  */
 protected function printStepDefinitionPath(StepNode $step, DefinitionInterface $definition)
 {
     if ($this->getParameter('paths')) {
         $type = $step->getType();
         $text = $this->inOutlineSteps ? $step->getCleanText() : $step->getText();
         $indent = $this->stepIndent;
         $nameLength = mb_strlen("{$indent}{$type} {$text}");
         $indentCount = $nameLength > $this->maxLineLength ? 0 : $this->maxLineLength - $nameLength;
         $this->printPathComment($this->relativizePathsInString($definition->getPath()), $indentCount);
         if ($this->getParameter('expand')) {
             $this->maxLineLength = max($this->maxLineLength, $nameLength);
         }
     } else {
         $this->writeln();
     }
 }
예제 #4
0
 /**
  * Dumps a step.
  *
  * @param StepNode $step Step node instance
  *
  * @return string
  *
  * @throws Exception if invalid step type providen
  */
 public function dumpStep(StepNode $step)
 {
     switch ($step->getType()) {
         case 'Given':
             $kw = $this->keywords->getGivenKeywords();
             break;
         case 'When':
             $kw = $this->keywords->getWhenKeywords();
             break;
         case 'Then':
             $kw = $this->keywords->getThenKeywords();
             break;
         case 'But':
             $kw = $this->keywords->getButKeywords();
             break;
         case 'And':
             $kw = $this->keywords->getAndKeywords();
             break;
         default:
             throw new Exception("invalid type given : " . $step->getType());
     }
     return $this->dumpText($kw . ' ' . $step->getText());
 }
예제 #5
0
    /**
     * Returns step definition for step node.
     *
     * @param   Behat\Gherkin\Node\StepNode     $step   step node
     *
     * @return  array   hash (md5_key => definition)
     */
    public function proposeDefinition(StepNode $step)
    {
        $text = $step->getText();
        $regex = preg_replace('/([\\[\\]\\(\\)\\\\^\\$\\.\\|\\?\\*\\+])/', '\\\\$1', $text);
        $regex = preg_replace(array('/\'([^\']*)\'/', '/\\"([^\\"]*)\\"/', '/(\\d+)/'), array("\\'([^\\']*)\\'", "\"([^\"]*)\"", "(\\d+)"), $regex, -1, $count);
        $regex = preg_replace('/\'.*(?<!\')/', '\\\\$0', $regex);
        // Single quotes without matching pair (escape in resulting regex)
        $args = array("\$world");
        for ($i = 0; $i < $count; $i++) {
            $args[] = "\$arg" . ($i + 1);
        }
        foreach ($step->getArguments() as $argument) {
            if ($argument instanceof PyStringNode) {
                $args[] = "\$string";
            } elseif ($argument instanceof TableNode) {
                $args[] = "\$table";
            }
        }
        $description = sprintf(<<<PHP
\$steps->%s('/^%s\$/', function(%s) {
    throw new \\Behat\\Behat\\Exception\\Pending();
});
PHP
, '%s', $regex, implode(', ', $args));
        return array(md5($description) => sprintf($description, str_replace(' ', '_', $step->getType())));
    }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 protected function printStepName(StepNode $step, DefinitionInterface $definition = null, $color)
 {
     $type = $step->getType();
     $text = $this->inOutlineSteps ? $step->getCleanText() : $step->getText();
     if (null !== $definition) {
         $text = $this->colorizeDefinitionArguments($text, $definition, $color);
     }
     $this->writeln('<span class="keyword">' . $type . ' </span>');
     $this->writeln('<span class="text">' . $text . '</span>');
 }
예제 #7
0
 /**
  * Prints path to step.
  *
  * @param   Behat\Gherkin\Node\StepNode         $step           step node
  * @param   Behat\Behat\Definition\Definition   $definition     definition (if step defined)
  * @param   Exception                           $exception      exception (if step failed)
  */
 protected function printStepPath(StepNode $step, Definition $definition = null, \Exception $exception = null)
 {
     $color = $exception instanceof Pending ? 'pending' : 'failed';
     $type = $step->getType();
     $text = $step->getText();
     $stepPath = "In step `{$type} {$text}'.";
     $stepPathLn = mb_strlen($stepPath);
     $node = $step->getParent();
     if ($node instanceof BackgroundNode) {
         $scenarioPath = "From scenario background.";
     } else {
         $title = $node->getTitle();
         $title = $title ? "`{$title}'" : '***';
         $scenarioPath = "From scenario {$title}.";
     }
     $scenarioPathLn = mb_strlen($scenarioPath);
     $this->maxLineLength = max($this->maxLineLength, $stepPathLn);
     $this->maxLineLength = max($this->maxLineLength, $scenarioPathLn);
     $this->write("    {+{$color}}{$stepPath}{-{$color}}");
     if (null !== $definition) {
         $indentCount = $this->maxLineLength - $stepPathLn;
         $this->printPathComment($definition->getFile(), $definition->getLine(), $indentCount);
     } else {
         $this->writeln();
     }
     $this->write("    {+{$color}}{$scenarioPath}{-{$color}}");
     $indentCount = $this->maxLineLength - $scenarioPathLn;
     $this->printPathComment($node->getFile(), $node->getLine(), $indentCount);
     $this->writeln();
 }
예제 #8
0
 /**
  * Prints step definition path.
  *
  * @param   Behat\Gherkin\Node\StepNode         $step       step node
  * @param   Behat\Behat\Definition\Definition   $definition definition (if found one)
  *
  * @uses    printPathComment()
  */
 protected function printStepDefinitionPath(StepNode $step, Definition $definition)
 {
     $type = $step->getType();
     $text = $this->inOutlineSteps ? $step->getCleanText() : $step->getText();
     $nameLength = mb_strlen("    {$type} {$text}");
     $indentCount = $nameLength > $this->maxLineLength ? 0 : $this->maxLineLength - $nameLength;
     $this->printPathComment($definition->getFile(), $definition->getLine(), $indentCount);
 }