/** * Searches and runs provided step with DefinitionDispatcher. * * @param Behat\Gherkin\Node\StepNode $step step node * * @return Behat\Behat\Event\StepEvent */ protected function executeStep(StepNode $step) { $context = $this->context; $result = null; $definition = null; $exception = null; $snippet = null; try { $definition = $this->definitions->findDefinition($this->context, $step); if ($this->skip) { return new StepEvent($step, $context, StepEvent::SKIPPED, $definition); } try { $this->executeStepDefinition($step, $definition); $result = StepEvent::PASSED; } catch (PendingException $e) { $result = StepEvent::PENDING; $exception = $e; } catch (\Exception $e) { $result = StepEvent::FAILED; $exception = $e; } } catch (UndefinedException $e) { $result = StepEvent::UNDEFINED; $snippet = $this->definitions->proposeDefinition($this->context, $step); $exception = $e; } catch (\Exception $e) { $result = StepEvent::FAILED; $exception = $e; } return new StepEvent($step, $context, $result, $definition, $exception, $snippet); }
/** * Visits & tests StepNode. * * @param Behat\Gherkin\Node\AbstractNode $step * * @return integer */ public function visit(AbstractNode $step) { $step->setTokens($this->tokens); $this->dispatcher->dispatch('beforeStep', new StepEvent($step, $this->environment)); $result = 0; $definition = null; $exception = null; $snippet = null; // Find proper definition try { $definition = $this->definitions->findDefinition($step); } catch (Ambiguous $e) { $result = StepEvent::FAILED; $exception = $e; } catch (Undefined $e) { $result = StepEvent::UNDEFINED; $snippet = $this->definitions->proposeDefinition($step); } // Run test if (0 === $result) { if (!$this->skip) { try { $definition->run($this->environment, $this->tokens); $result = StepEvent::PASSED; } catch (Pending $e) { $result = StepEvent::PENDING; $exception = $e; } catch (\Exception $e) { $result = StepEvent::FAILED; $exception = $e; } } else { $result = StepEvent::SKIPPED; } } $this->dispatcher->dispatch('afterStep', new StepEvent($step, $this->environment, $result, $definition, $exception, $snippet)); return $result; }