/** * Visits & tests OutlineNode example. * * @param Behat\Gherkin\Node\OutlineNode $outline * @param integer $row row number * @param array $tokens step replacements for tokens * * @return integer */ protected function visitOutlineExample(OutlineNode $outline, $row, array $tokens = array()) { $environment = $this->container->get('behat.environment_builder')->build(); $itResult = 0; $skip = false; $this->dispatcher->dispatch('beforeOutlineExample', new OutlineExampleEvent($outline, $row, $environment)); // Visit & test background if has one if ($outline->getFeature()->hasBackground()) { $bgResult = $this->visitBackground($outline->getFeature()->getBackground(), $environment); if (0 !== $bgResult) { $skip = true; } $itResult = max($itResult, $bgResult); } // Visit & test steps foreach ($outline->getSteps() as $step) { $stResult = $this->visitStep($step, $environment, $tokens, $skip); if (0 !== $stResult) { $skip = true; } $itResult = max($itResult, $stResult); } $this->dispatcher->dispatch('afterOutlineExample', new OutlineExampleEvent($outline, $row, $environment, $itResult, $skip)); return $itResult; }
/** * Visits & tests BackgroundNode. * * @param Behat\Gherkin\Node\AbstractNode $background * * @return integer */ public function visit(AbstractNode $background) { $this->dispatcher->dispatch('beforeBackground', new BackgroundEvent($background)); $result = 0; $skip = false; // Visit & test steps foreach ($background->getSteps() as $step) { $tester = $this->container->get('behat.tester.step'); $tester->setEnvironment($this->environment); $tester->skip($skip); $stResult = $step->accept($tester); if (0 !== $stResult) { $skip = true; } $result = max($result, $stResult); } $this->dispatcher->dispatch('afterBackground', new BackgroundEvent($background, $result, $skip)); return $result; }
/** * Visits & tests FeatureNode. * * @param Behat\Gherkin\Node\AbstractNode $feature * * @return integer * * @throws BehaviorException if unknown scenario type (neither Outline or Scenario) found in feature */ public function visit(AbstractNode $feature) { $result = 0; // If feature has scenario - run them if (count($scenarios = $feature->getScenarios())) { $this->dispatcher->dispatch('beforeFeature', new FeatureEvent($feature)); foreach ($scenarios as $scenario) { if ($scenario instanceof OutlineNode) { $tester = $this->container->get('behat.tester.outline'); } elseif ($scenario instanceof ScenarioNode) { $tester = $this->container->get('behat.tester.scenario'); } else { throw new BehaviorException('Unknown scenario type found: ' . get_class($scenario)); } $result = max($result, $scenario->accept($tester)); } $this->dispatcher->dispatch('afterFeature', new FeatureEvent($feature, $result)); } return $result; }
/** * Visits & tests ScenarioNode. * * @param Behat\Gherkin\Node\AbstractNode $scenario * * @return integer */ public function visit(AbstractNode $scenario) { $this->dispatcher->dispatch('beforeScenario', new ScenarioEvent($scenario, $this->context)); $result = 0; $skip = false; // Visit & test background if has one if ($scenario->getFeature()->hasBackground()) { $bgResult = $this->visitBackground($scenario->getFeature()->getBackground(), $this->context); if (0 !== $bgResult) { $skip = true; } $result = max($result, $bgResult); } // Visit & test steps foreach ($scenario->getSteps() as $step) { $stResult = $this->visitStep($step, $this->context, array(), $skip); if (0 !== $stResult) { $skip = true; } $result = max($result, $stResult); } $this->dispatcher->dispatch('afterScenario', new ScenarioEvent($scenario, $this->context, $result, $skip)); return $result; }
/** * 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; }