public function preload() { $this->getMetadata()->setGroups($this->featureNode->getTags()); $this->getMetadata()->setGroups($this->scenarioNode->getTags()); $this->scenario->setMetaStep(null); if ($background = $this->featureNode->getBackground()) { foreach ($background->getSteps() as $step) { $this->validateStep($step); } } foreach ($this->scenarioNode->getSteps() as $step) { $this->validateStep($step); } }
/** * Dumps feature. * * @param FeatureNode $feature Feature instance * * @return string */ public function dumpFeature(FeatureNode $feature) { $language = $feature->getLanguage(); $this->keywords->setLanguage($language); $content = '' . $this->dumpLanguage($language) . ($feature->getTags() ? PHP_EOL . $this->dumpTags($feature->getTags(), 0) : '') . PHP_EOL . $this->dumpKeyword($this->keywords->getFeatureKeywords(), $feature->getTitle(), 0) . PHP_EOL . $this->dumpText($feature->getDescription(), 1); if ($feature->getBackground()) { $content .= $this->dumpBackground($feature->getBackground()); } $scenarios = $feature->getScenarios(); foreach ($scenarios as $scenario) { $content .= PHP_EOL . $this->dumpScenario($scenario); } return $content; }
public function testTags() { $feature = new FeatureNode(); $this->assertFalse($feature->hasTags()); $this->assertInternalType('array', $feature->getTags()); $this->assertEquals(0, count($feature->getTags())); $feature->setTags($tags = array('tag1', 'tag2')); $this->assertEquals($tags, $feature->getTags()); $feature->addTag('tag3'); $this->assertEquals(array('tag1', 'tag2', 'tag3'), $feature->getTags()); $this->assertFalse($feature->hasTag('tag4')); $this->assertTrue($feature->hasTag('tag2')); $this->assertTrue($feature->hasTag('tag3')); }
/** * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrine * @param \Doctrine\Common\Persistence\ObjectManager $manager * @param \Behat\Behat\Hook\Scope\ScenarioScope $event * @param \Behat\Gherkin\Node\FeatureNode $feature * @param \Behat\Gherkin\Node\ScenarioNode $scenario * @param \Knp\FriendlyContexts\Alice\Loader\Yaml $loader * @param \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory $metadataFactory * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $userMetadata * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $placeMetadata * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $productMetadata */ function let($container, $doctrine, $manager, $event, $loader, $feature, $scenario, $metadataFactory, $userMetadata, $placeMetadata, $productMetadata) { $doctrine->getManager()->willReturn($manager); $feature->getTags()->willReturn(['alice(Place)', 'admin']); $scenario->getTags()->willReturn(['alice(User)']); $event->getFeature()->willReturn($feature); $event->getScenario()->willReturn($scenario); $loader->load('user.yml')->willReturn([]); $loader->load('product.yml')->willReturn([]); $loader->load('place.yml')->willReturn([]); $loader->getCache()->willReturn([]); $loader->clearCache()->willReturn(null); $fixtures = ['User' => 'user.yml', 'Product' => 'product.yml', 'Place' => 'place.yml']; $config = ['alice' => ['fixtures' => $fixtures, 'dependencies' => []]]; $container->has(Argument::any())->willReturn(true); $container->hasParameter(Argument::any())->willReturn(true); $container->get('friendly.alice.loader.yaml')->willReturn($loader); $container->get('doctrine')->willReturn($doctrine); $container->getParameter('friendly.alice.fixtures')->willReturn($fixtures); $container->getParameter('friendly.alice.dependencies')->willReturn([]); $manager->getMetadataFactory()->willReturn($metadataFactory); $metadataFactory->getAllMetadata()->willReturn([$userMetadata, $placeMetadata, $productMetadata]); $userMetadata->getName()->willReturn('User'); $placeMetadata->getName()->willReturn('Place'); $productMetadata->getName()->willReturn('Product'); $this->initialize($config, $container); }
public function preload() { $this->getMetadata()->setGroups($this->featureNode->getTags()); $this->getMetadata()->setGroups($this->scenarioNode->getTags()); $this->scenario->setMetaStep(null); if ($background = $this->featureNode->getBackground()) { foreach ($background->getSteps() as $step) { $this->validateStep($step); } } foreach ($this->scenarioNode->getSteps() as $step) { $this->validateStep($step); } if ($this->getMetadata()->getIncomplete()) { $this->getMetadata()->setIncomplete($this->getMetadata()->getIncomplete() . "\nRun gherkin:snippets to define missing steps"); } }
/** * {@inheritdoc} */ public function printHeader(Formatter $formatter, FeatureNode $feature) { if ($feature instanceof TaggedNodeInterface) { $this->printTags($formatter->getOutputPrinter(), $feature->getTags()); } $this->printTitle($formatter->getOutputPrinter(), $feature); $this->printDescription($formatter->getOutputPrinter(), $feature); }
/** * Filters feature according to the filter. * * @param FeatureNode $feature * * @return FeatureNode */ public function filterFeature(FeatureNode $feature) { $scenarios = array(); foreach ($feature->getScenarios() as $scenario) { if (!$this->isScenarioMatch($scenario)) { continue; } if ($scenario instanceof OutlineNode && $scenario->hasExamples()) { $table = $scenario->getExampleTable()->getTable(); $lines = array_keys($table); $filteredTable = array($lines[0] => $table[$lines[0]]); unset($table[$lines[0]]); foreach ($table as $line => $row) { if ($this->filterMinLine <= $line && $this->filterMaxLine >= $line) { $filteredTable[$line] = $row; } } $scenario = new OutlineNode($scenario->getTitle(), $scenario->getTags(), $scenario->getSteps(), new ExampleTableNode($filteredTable, $scenario->getExampleTable()->getKeyword()), $scenario->getKeyword(), $scenario->getLine()); } $scenarios[] = $scenario; } return new FeatureNode($feature->getTitle(), $feature->getDescription(), $feature->getTags(), $feature->getBackground(), $scenarios, $feature->getKeyword(), $feature->getLanguage(), $feature->getFile(), $feature->getLine()); }
/** * Checks if scenario or outline matches specified filter. * * @param FeatureNode $feature Feature node instance * @param ScenarioInterface $scenario Scenario or Outline node instance * * @return Boolean */ public function isScenarioMatch(FeatureNode $feature, ScenarioInterface $scenario) { return $this->isTagsMatchCondition(array_merge($feature->getTags(), $scenario->getTags())); }
public function getTags() { return $this->featureNode->getTags(); }