public function addSnippet(StepNode $step)
 {
     $args = [];
     $pattern = $step->getText();
     // match numbers (not in quotes)
     if (preg_match_all('~([\\d\\.])(?=([^"]*"[^"]*")*[^"]*$)~', $pattern, $matches)) {
         foreach ($matches[1] as $num => $param) {
             $num++;
             $args[] = '$num' . $num;
             $pattern = str_replace($param, ":num{$num}", $pattern);
         }
     }
     // match quoted string
     if (preg_match_all('~"(.*?)"~', $pattern, $matches)) {
         foreach ($matches[1] as $num => $param) {
             $num++;
             $args[] = '$arg' . $num;
             $pattern = str_replace('"' . $param . '"', ":arg{$num}", $pattern);
         }
     }
     if (in_array($pattern, $this->processed)) {
         return;
     }
     $methodName = preg_replace('~(\\s+?|\'|\\"|\\W)~', '', ucwords(preg_replace('~"(.*?)"|\\d+~', '', $step->getText())));
     $this->snippets[] = (new Template($this->template))->place('type', $step->getKeywordType())->place('text', $pattern)->place('methodName', lcfirst($methodName))->place('params', implode(', ', $args))->produce();
     $this->processed[] = $pattern;
 }
Пример #2
0
 public function addSnippet(StepNode $step)
 {
     $args = [];
     $pattern = $step->getText();
     if (preg_match_all('~"(.*?)"~', $pattern, $matches)) {
         foreach ($matches[1] as $num => $param) {
             $num++;
             $args[] = '$arg' . $num;
             $pattern = str_replace('"' . $param . '"', ":arg{$num}", $pattern);
         }
     }
     $methodName = preg_replace('~(\\s+?|\'|\\")~', '', ucwords(preg_replace('~"(.*?)"~', '', $step->getText())));
     $this->snippets[] = (new Template($this->template))->place('type', $step->getKeywordType())->place('text', $pattern)->place('methodName', lcfirst($methodName))->place('params', implode(', ', $args))->produce();
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function getSnippet()
 {
     return sprintf($this->template, $this->step->getKeywordType());
 }