/** * {@inheritdoc} */ protected function printFeatureOrScenarioTags(AbstractNode $node) { if (count($tags = $node->getOwnTags())) { $this->writeln('<ul class="tags">'); foreach ($tags as $tag) { $this->writeln("<li>@{$tag}</li>"); } $this->writeln('</ul>'); } }
/** * Visits & tests OutlineNode. * * @param AbstractNode $outline * * @return integer */ public function visit(AbstractNode $outline) { $this->dispatcher->dispatch('beforeOutline', new OutlineEvent($outline)); $result = 0; // Run examples of outline foreach ($outline->getExamples()->getHash() as $iteration => $tokens) { $itResult = $this->visitOutlineExample($outline, $iteration, $tokens); $result = max($result, $itResult); } $this->dispatcher->dispatch('afterOutline', new OutlineEvent($outline, $result)); return $result; }
/** * Checks that node matches condition. * * @param Behat\Gherkin\Node\Node\AbstractNode $node node to check */ protected function matchesCondition(AbstractNode $node) { $satisfies = true; foreach (explode('&&', $this->filterString) as $andTags) { $satisfiesComma = false; foreach (explode(',', $andTags) as $tag) { $tag = str_replace('@', '', trim($tag)); if ('~' === $tag[0]) { $tag = mb_substr($tag, 1); $satisfiesComma = !$node->hasTag($tag) || $satisfiesComma; } else { $satisfiesComma = $node->hasTag($tag) || $satisfiesComma; } } $satisfies = false !== $satisfiesComma && $satisfies && $satisfiesComma || false; } return $satisfies; }
/** * 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 FeatureNode. * * @param AbstractNode $feature * * @return integer * * @throws BehaviorException if unknown scenario type (neither Outline or Scenario) found in feature */ public function visit(AbstractNode $feature) { $this->dispatcher->dispatch('beforeFeature', new FeatureEvent($feature, $this->parameters)); $result = 0; $skip = false; // Visit & test scenarios foreach ($feature->getScenarios() 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)); } $tester->setSkip($skip || $this->skip); $result = max($result, $scenario->accept($tester)); } $this->dispatcher->dispatch('afterFeature', new FeatureEvent($feature, $this->parameters, $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; }
/** * Returns feature or scenario name. * * @param AbstractNode $node * @param Boolean $haveBaseIndent * * @return string */ protected function getFeatureOrScenarioName(AbstractNode $node, $haveBaseIndent = true) { $keyword = $node->getKeyword(); $baseIndent = $node instanceof FeatureNode || !$haveBaseIndent ? '' : ' '; $lines = explode("\n", $node->getTitle()); $title = array_shift($lines); if (count($lines)) { foreach ($lines as $line) { $title .= "\n" . $baseIndent . ' ' . $line; } } return "{$baseIndent}{$keyword}:" . ($title ? ' ' . $title : ''); }
/** * Parse tags for the feature/scenario/outline node. * * @param Node\AbstractNode $node */ private function parseNodeTags(Node\AbstractNode $node) { $this->skipComments(); while ('Tag' === $this->predictTokenType()) { $node->setTags($this->lexer->getAdvancedToken()->tags); $this->skipComments(); } }
/** * 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; }
/** * 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->context)); $afterEvent = $this->executeStep($step); $this->dispatcher->dispatch('afterStep', $afterEvent); return $afterEvent->getResult(); }