/** * Defines a step with ->Given|When|Then|...('/regex/', callback) or * call a step with ->Given|When|Then|...('I enter "12" in the field', $world) or * even with arguments ->Given|When|Then|...('I fill up fields', $world, $table). * * @param string $type step type (Given|When|Then|...) * @param string $arguments step regex & callback * * @throws Behat\Behat\Exception\RedundantException if step definition is already exists */ public function __call($type, $arguments) { if (2 == count($arguments) && is_callable($arguments[1])) { switch (strtolower($type)) { case 'when': $definition = new When($arguments[1], $arguments[0]); break; case 'then': $definition = new Then($arguments[1], $arguments[0]); break; case 'given': default: $definition = new Given($arguments[1], $arguments[0]); break; } $this->dispatcher->addDefinition($definition); } else { $text = array_shift($arguments); $world = array_shift($arguments); $step = new StepNode($type, $text); $step->setArguments($arguments); $definition = $this->dispatcher->findDefinition($world, $step); $definition->run($world); } return $this; }
/** * @see Behat\Behat\Context\Loader\ContextLoaderInterface::load() */ public function load(ContextInterface $context) { $reflection = new \ReflectionObject($context); foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodRefl) { foreach ($this->readMethodAnnotations($reflection->getName(), $methodRefl) as $annotation) { if ($annotation instanceof DefinitionInterface) { $this->definitionDispatcher->addDefinition($annotation); } elseif ($annotation instanceof TransformationInterface) { $this->definitionDispatcher->addTransformation($annotation); } elseif ($annotation instanceof HookInterface) { $this->hookDispatcher->addHook($annotation); } } } }
public function initialize() { if ($this->initialized) { return true; } $keywords = new \Behat\Gherkin\Keywords\ArrayKeywords(array('en' => array('feature' => 'Feature', 'background' => 'Background', 'scenario' => 'Scenario', 'scenario_outline' => 'Scenario Outline|Scenario Template', 'examples' => 'Examples|Scenarios', 'given' => 'Given', 'when' => 'When', 'then' => 'Then', 'and' => 'And', 'but' => 'But'))); $keywords->setLanguage('en'); $lexer = new \Behat\Gherkin\Lexer($keywords); $parser = new Parser($lexer); foreach ($this->getParameter('templates') as $template) { foreach (glob($template) as $file) { /** @var $feature \Behat\Gherkin\Node\FeatureNode */ $feature = $parser->parse(file_get_contents($file)); /** @var $scenario \Behat\Gherkin\Node\ScenarioNode */ foreach ($feature->getScenarios() as $scenario) { $this->definitionDispatcher->addDefinition(new \Weavora\MinkExtra\Definition\LazyDefinition($scenario)); } } } $this->initialized = true; return true; }
public function load(ContextInterface $context) { foreach ($this->sitemap->findClasses() as $className) { $reflection = new \ReflectionClass($className); if ($reflection->isSubclassOf('Behat\\Behat\\Context\\BehatContext')) { continue; } foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodRefl) { if ($methodRefl->getDeclaringClass() != $reflection) { continue; } // only own methods; intentionally != because reflection is not identical foreach ($this->readMethodAnnotations($reflection->getName(), $methodRefl) as $annotation) { if ($annotation instanceof \Behat\Behat\Definition\DefinitionInterface) { $this->definitionDispatcher->addDefinition($annotation); } elseif ($annotation instanceof \Behat\Behat\Definition\TransformationInterface) { $this->definitionDispatcher->addTransformation($annotation); } elseif ($annotation instanceof \Behat\Behat\Hook\HookInterface) { $this->hookDispatcher->addHook($annotation); } } } } }