Exemple #1
0
 /**
  * Define a step with ->Given('/regex/', callback) or
  * call a step with ->Given('I enter "12" in the field', $world) or
  * even with arguments ->Given('I fill up fields', $world, $table).
  *
  * @param   string  $type       step type (Given/When/Then/And or localized one)
  * @param   string  $arguments  step regex & callback
  * 
  * @throws  Everzet\Behat\Exception\Redundant  if step definition is already exists
  */
 public function __call($type, $arguments)
 {
     if (2 == count($arguments) && is_callable($arguments[1])) {
         $debug = debug_backtrace();
         $debug = $debug[1];
         $this->objects[] = new Definition($type, $arguments[0], $arguments[1], $debug['file'], $debug['line']);
     } else {
         $text = array_shift($arguments);
         $world = array_shift($arguments);
         $step = new StepNode($type, $text);
         $step->setArguments($arguments);
         $this->dispatcher->notify(new Event($step, 'step.run', array('world' => $world)));
     }
     return $this;
 }
Exemple #2
0
 /**
  * Check If Step Matches Specified Filter. 
  * 
  * @param   StepNode    $step       step
  * @param   string      $filter     filter string (optional)
  */
 public function isStepMatchFilter(StepNode $step, $filter = null)
 {
     $scenario = $step->getParent();
     $feature = $scenario->getFeature();
     return $this->isClosuresMatchFilter(function ($tag) use($feature, $scenario) {
         return $scenario->hasTag($tag) || $feature->hasTag($tag);
     }, function ($tag) use($feature, $scenario) {
         return !$scenario->hasTag($tag) && !$feature->hasTag($tag);
     }, null !== $filter ? $filter : $this->filterString);
 }
 /**
  * Find step definition, that match specified step.
  *
  * @param   StepNode     $step       step
  * 
  * @return  StepDefinition
  * 
  * @throws  Everzet\Behat\Exception\Ambiguous  if step description is ambiguous
  * @throws  Everzet\Behat\Exception\Undefined  if step definition not found
  */
 public function findDefinition(StepNode $step)
 {
     if (!count($this->definitions)) {
         $this->loadDefinitions();
     }
     $text = $step->getText();
     $args = $step->getArguments();
     $matches = array();
     // find step to match
     foreach ($this->definitions as $regex => $definition) {
         if (preg_match($regex, $text, $arguments)) {
             $arguments = array_merge(array_slice($arguments, 1), $args);
             // transform arguments
             foreach ($this->transformations as $transformation) {
                 foreach ($arguments as $num => $argument) {
                     if ($newArgument = $transformation->transform($argument)) {
                         $arguments[$num] = $newArgument;
                     }
                 }
             }
             // set matched definition
             $definition->setMatchedText($text);
             $definition->setValues($arguments);
             $matches[] = $definition;
         }
     }
     if (count($matches) > 1) {
         throw new Ambiguous($text, $matches);
     }
     if (0 === count($matches)) {
         throw new Undefined($text);
     }
     return $matches[0];
 }
Exemple #4
0
 /**
  * Check If Step Matches Specified Filter. 
  * 
  * @param   StepNode    $step       step
  * @param   string      $filter     filter string (optional)
  */
 public function isStepMatchFilter(StepNode $step, $filter = null)
 {
     $filter = null !== $filter ? $filter : $this->filterString;
     $scenario = $step->getParent();
     $feature = $scenario->getFeature();
     if ('/' === $filter[0]) {
         return preg_match($filter, $scenario->getTitle()) || preg_match($filter, $feature->getTitle());
     }
     return false !== mb_strpos($scenario->getTitle(), $filter) || false !== mb_strpos($feature->getTitle(), $filter);
 }