Dumps keyworded feature into string.
/** * Prints example story syntax into console. * * @param Symfony\Component\Console\Output\OutputInterface $output * @param string $language */ public function printSyntax(OutputInterface $output, $language = 'en') { $output->getFormatter()->setStyle('comment', new OutputFormatterStyle('yellow')); $output->getFormatter()->setStyle('keyword', new OutputFormatterStyle('green', null, array('bold'))); $story = $this->dumper->dump($language); $story = preg_replace('/^\\#.*/', '<comment>$0</comment>', $story); $output->writeln($story); }
/** * Executes controller. * * @param InputInterface $input * @param OutputInterface $output * * @return null|integer */ public function execute(InputInterface $input, OutputInterface $output) { if (!$input->getOption('story-syntax')) { return null; } $output->getFormatter()->setStyle('gherkin_keyword', new OutputFormatterStyle('green', null, array('bold'))); $output->getFormatter()->setStyle('gherkin_comment', new OutputFormatterStyle('yellow')); $story = $this->keywordsDumper->dump($this->translator->getLocale()); $story = preg_replace('/^\\#.*/', '<gherkin_comment>$0</gherkin_comment>', $story); $output->writeln($story); $output->writeln(''); return 0; }
public function testExtendedVersionDumper() { $dumper = new KeywordsDumper($this->keywords); $dumped = $dumper->dump('ru', false); $etalon = array(<<<GHERKIN # language: ru Функционал: Internal operations In order to stay secret As a secret organization We need to be able to erase past agents' memory Предыстория: Допустим there is agent A И there is agent B Сценарий: Erasing agent memory Допустим there is agent J И there is agent K Если I erase agent K's memory @ I erase agent K's memory То there should be agent J Но there should not be agent K История: Erasing agent memory Допустим there is agent J И there is agent K Если I erase agent K's memory @ I erase agent K's memory То there should be agent J Но there should not be agent K Структура сценария: Erasing other agents' memory Допустим there is agent <agent1> И there is agent <agent2> Если I erase agent <agent2>'s memory @ I erase agent <agent2>'s memory То there should be agent <agent1> Но there should not be agent <agent2> Значения: | agent1 | agent2 | | D | M | Аутлайн: Erasing other agents' memory Допустим there is agent <agent1> И there is agent <agent2> Если I erase agent <agent2>'s memory @ I erase agent <agent2>'s memory То there should be agent <agent1> Но there should not be agent <agent2> Значения: | agent1 | agent2 | | D | M | GHERKIN , <<<GHERKIN # language: ru Фича: Internal operations In order to stay secret As a secret organization We need to be able to erase past agents' memory Предыстория: Допустим there is agent A И there is agent B Сценарий: Erasing agent memory Допустим there is agent J И there is agent K Если I erase agent K's memory @ I erase agent K's memory То there should be agent J Но there should not be agent K История: Erasing agent memory Допустим there is agent J И there is agent K Если I erase agent K's memory @ I erase agent K's memory То there should be agent J Но there should not be agent K Структура сценария: Erasing other agents' memory Допустим there is agent <agent1> И there is agent <agent2> Если I erase agent <agent2>'s memory @ I erase agent <agent2>'s memory То there should be agent <agent1> Но there should not be agent <agent2> Значения: | agent1 | agent2 | | D | M | Аутлайн: Erasing other agents' memory Допустим there is agent <agent1> И there is agent <agent2> Если I erase agent <agent2>'s memory @ I erase agent <agent2>'s memory То there should be agent <agent1> Но there should not be agent <agent2> Значения: | agent1 | agent2 | | D | M | GHERKIN ); $this->assertEquals($etalon, $dumped); }
public function translationTestDataProvider() { $keywords = $this->getKeywords(); $lexer = new Lexer($keywords); $parser = new Parser($lexer); $dumper = new KeywordsDumper($keywords); $keywordsArray = $this->getKeywordsArray(); // Remove languages with repeated keywords unset($keywordsArray['en-old'], $keywordsArray['uz']); $data = array(); foreach ($keywordsArray as $lang => $i18nKeywords) { $features = array(); foreach (explode('|', $i18nKeywords['feature']) as $transNum => $featureKeyword) { $line = 1; if ('en' !== $lang) { $line = 2; } $featureLine = $line; $line += 5; $keywords = explode('|', $i18nKeywords['background']); $backgroundLine = $line; $line += 1; $background = new BackgroundNode(null, array_merge($this->getSteps($i18nKeywords['given'], 'there is agent A', $line, 'Given'), $this->getSteps($i18nKeywords['and'], 'there is agent B', $line, 'Given')), $keywords[0], $backgroundLine); $line += 1; $scenarios = array(); foreach (explode('|', $i18nKeywords['scenario']) as $scenarioKeyword) { $scenarioLine = $line; $line += 1; $steps = array_merge($this->getSteps($i18nKeywords['given'], 'there is agent J', $line, 'Given'), $this->getSteps($i18nKeywords['and'], 'there is agent K', $line, 'Given'), $this->getSteps($i18nKeywords['when'], 'I erase agent K\'s memory', $line, 'When'), $this->getSteps($i18nKeywords['then'], 'there should be agent J', $line, 'Then'), $this->getSteps($i18nKeywords['but'], 'there should not be agent K', $line, 'Then')); $scenarios[] = new ScenarioNode('Erasing agent memory', array(), $steps, $scenarioKeyword, $scenarioLine); $line += 1; } foreach (explode('|', $i18nKeywords['scenario_outline']) as $outlineKeyword) { $outlineLine = $line; $line += 1; $steps = array_merge($this->getSteps($i18nKeywords['given'], 'there is agent <agent1>', $line, 'Given'), $this->getSteps($i18nKeywords['and'], 'there is agent <agent2>', $line, 'Given'), $this->getSteps($i18nKeywords['when'], 'I erase agent <agent2>\'s memory', $line, 'When'), $this->getSteps($i18nKeywords['then'], 'there should be agent <agent1>', $line, 'Then'), $this->getSteps($i18nKeywords['but'], 'there should not be agent <agent2>', $line, 'Then')); $line += 1; $keywords = explode('|', $i18nKeywords['examples']); $table = new ExampleTableNode(array(++$line => array('agent1', 'agent2'), ++$line => array('D', 'M')), $keywords[0]); $line += 1; $scenarios[] = new OutlineNode('Erasing other agents\' memory', array(), $steps, $table, $outlineKeyword, $outlineLine); $line += 1; } $features[] = new FeatureNode('Internal operations', <<<DESC In order to stay secret As a secret organization We need to be able to erase past agents' memory DESC , array(), $background, $scenarios, $featureKeyword, $lang, $lang . '_' . ($transNum + 1) . '.feature', $featureLine); } $dumped = $dumper->dump($lang, false, true); $parsed = array(); try { foreach ($dumped as $num => $dumpedFeature) { $parsed[] = $parser->parse($dumpedFeature, $lang . '_' . ($num + 1) . '.feature'); } } catch (\Exception $e) { throw new \Exception($e->getMessage() . ":\n" . json_encode($dumped), 0, $e); } $data[] = array($lang, $features, $parsed); } return $data; }
public function translationTestDataProvider() { $keywords = $this->getKeywords(); $lexer = new Lexer($keywords); $parser = new Parser($lexer); $dumper = new KeywordsDumper($keywords); $data = array(); foreach ($this->getKeywordsArray() as $lang => $i18nKeywords) { $features = array(); foreach (explode('|', $i18nKeywords['feature']) as $transNum => $featureKeyword) { $line = 1; if ('en' !== $lang) { $line = 2; } $feature = new Node\FeatureNode('Internal operations', <<<DESC In order to stay secret As a secret organization We need to be able to erase past agents' memory DESC , $lang . '_' . ($transNum + 1) . '.feature', $line); $feature->setLanguage($lang); $feature->setKeyword($featureKeyword); $line += 5; $background = new Node\BackgroundNode(null, $line); $keywords = explode('|', $i18nKeywords['background']); $background->setKeyword($keywords[0]); $line += 1; $line = $this->addSteps($background, $i18nKeywords['given'], 'there is agent A', $line); $line = $this->addSteps($background, $i18nKeywords['and'], 'there is agent B', $line); $feature->setBackground($background); $line += 1; foreach (explode('|', $i18nKeywords['scenario']) as $scenarioKeyword) { $scenario = new Node\ScenarioNode('Erasing agent memory', $line); $scenario->setKeyword($scenarioKeyword); $line += 1; $line = $this->addSteps($scenario, $i18nKeywords['given'], 'there is agent J', $line); $line = $this->addSteps($scenario, $i18nKeywords['and'], 'there is agent K', $line); $line = $this->addSteps($scenario, $i18nKeywords['when'], 'I erase agent K\'s memory', $line); $line = $this->addSteps($scenario, $i18nKeywords['then'], 'there should be agent J', $line); $line = $this->addSteps($scenario, $i18nKeywords['but'], 'there should not be agent K', $line); $feature->addScenario($scenario); $line += 1; } foreach (explode('|', $i18nKeywords['scenario_outline']) as $outlineKeyword) { $outline = new Node\OutlineNode('Erasing other agents\' memory', $line); $outline->setKeyword($outlineKeyword); $line += 1; $line = $this->addSteps($outline, $i18nKeywords['given'], 'there is agent <agent1>', $line); $line = $this->addSteps($outline, $i18nKeywords['and'], 'there is agent <agent2>', $line); $line = $this->addSteps($outline, $i18nKeywords['when'], 'I erase agent <agent2>\'s memory', $line); $line = $this->addSteps($outline, $i18nKeywords['then'], 'there should be agent <agent1>', $line); $line = $this->addSteps($outline, $i18nKeywords['but'], 'there should not be agent <agent2>', $line); $line += 1; $outline->setExamples($examples = new Node\TableNode(<<<TABLE | agent1 | agent2 | | D | M | TABLE )); $keywords = explode('|', $i18nKeywords['examples']); $examples->setKeyword($keywords[0]); $line += 3; $feature->addScenario($outline); $line += 1; } $features[] = $feature; } $dumped = $dumper->dump($lang, false); $parsed = array(); try { foreach ($dumped as $num => $dumpedFeature) { $parsed[] = $parser->parse($dumpedFeature, $lang . '_' . ($num + 1) . '.feature'); } } catch (\Exception $e) { throw new \Exception($e->getMessage() . ":\n" . $dumped, 0, $e); } $data[] = array($lang, $features, $parsed); } return $data; }
/** * Prints features usage example in specified language (--lang) to the console. * * @param Behat\Gherkin\Keywords\KeywordsDumper $dumper keywords dumper * @param string $lang locale name * @param Symfony\Component\Console\Input\OutputInterface $output output console */ protected function demonstrateUsageExample(KeywordsDumper $dumper, $lang, OutputInterface $output) { $output->setDecorated(false); $output->writeln($dumper->dump($lang) . "\n", OutputInterface::OUTPUT_RAW); }