public function testCanFormatFeatureDescription()
    {
        $expected = <<<EOS
    @kawaii @kawaii-bug-12
    Scenario: Not all people who program php are becoming kawaii
        Given I am a Java programmer
          And I am not Kawaii
         When I start to contribute to a php project:
            | project                  |
            | malukenho/kawaii-gherkin |
         Then I start to love php
         When I go to a php events
         Then I start to become a Kawaii guy

EOS;
        $tableNode = new TableNode([['project'], ['malukenho/kawaii-gherkin']]);
        $scenario = new ScenarioNode(' Not all people who program php are becoming kawaii ', [' kawaii ', ' kawaii-bug-12 '], [new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'), new StepNode('And', '  I am not Kawaii ', [], 2, 'And'), new StepNode('When', '  I start to contribute to a php project: ', [$tableNode], 3, 'And'), new StepNode('Then', '  I start to love php ', [], 4, 'And'), new StepNode('When', ' I go to a php events ', [], 5, 'And'), new StepNode('Then', 'I start to become a Kawaii guy ', [], 5, 'And')], 'Scenario', 1);
        self::assertSame($expected, $this->formatter->format($scenario));
    }
Пример #2
0
    public function testShouldCallExampleFormatterWhenExamplesIsProvided()
    {
        $expected = <<<EOS
    Scenario: Working a lot
         When I am working for <number> hours
         Then I have to be upset

        Examples:
          | number |
          | 10     |
          | 12     |

EOS;
        $scenario = new OutlineNode("Working a lot", [], [new StepNode('When', 'I am working for <number> hours', [], 1, 'When'), new StepNode('Then', 'I have to be upset', [], 2, 'Then')], new ExampleTableNode([['number'], ['10'], ['12']], 'Examples'), 'Scenario', 1);
        self::assertSame($expected, $this->formatter->format([$scenario]));
    }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $align = $input->getOption('align') === Step::ALIGN_TO_LEFT ? Step::ALIGN_TO_LEFT : Step::ALIGN_TO_RIGHT;
     $directory = $input->getArgument('directory');
     $finder = (new FeatureResolve($directory))->__invoke();
     $output->writeln("\nFinding files on <info>" . $directory . "</info>\n");
     $tagFormatter = new Tags();
     $featureDescription = new FeatureDescription();
     $background = new Background($align);
     $scenario = new Scenario($align);
     /* @var $file \Symfony\Component\Finder\SplFileInfo */
     foreach ($finder as $file) {
         $fileContent = $file->getContents();
         $feature = $this->parser->parse($fileContent);
         $formatted = $feature->hasTags() ? $tagFormatter->format($feature->getTags()) . "\n" : '';
         $formatted .= $featureDescription->format($feature) . "\n\n";
         $formatted .= $feature->hasBackground() ? $background->format($feature->getBackground()) . "\n" : '';
         $formatted .= $feature->hasScenarios() ? $scenario->format($feature->getScenarios()) : '';
         $filePointer = $file->openFile('w');
         $filePointer->fwrite($formatted);
         $output->writeln('<info>' . $file->getRealPath() . '</info>');
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $directory = $input->getArgument('directory');
     $finder = new Finder();
     $finder->files()->in($directory)->name('*.feature');
     $output->writeln('');
     $output->writeln('Finding files on <info>' . $directory . '</info>');
     /* @var $file \Symfony\Component\Finder\SplFileInfo */
     foreach ($finder as $file) {
         $feature = $this->parser->parse(file_get_contents($file->getRealpath()));
         $tagFormatter = new Tags();
         $featureDescription = new FeatureDescription();
         $background = new Background();
         $scenario = new Scenario();
         $formatted = $feature->hasTags() ? $tagFormatter->format($feature->getTags()) . PHP_EOL : '';
         $formatted .= $featureDescription->format($feature->getTitle(), explode(PHP_EOL, $feature->getDescription())) . PHP_EOL . PHP_EOL;
         $formatted .= $feature->hasBackground() ? $background->format($feature->getBackground()) . PHP_EOL . PHP_EOL : '';
         $formatted .= $feature->hasScenarios() ? $scenario->format(...$feature->getScenarios()) : '';
         $filePointer = $file->openFile('w');
         $filePointer->fwrite($formatted);
         $output->writeln('');
         $output->writeln('<info>' . $file->getRealpath() . '</info>');
     }
 }
 /**
  * {@inheritDoc}
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws ParserException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $align = $input->getOption('align') === Step::ALIGN_TO_LEFT ? Step::ALIGN_TO_LEFT : Step::ALIGN_TO_RIGHT;
     $directory = $input->getArgument('directory');
     $finder = (new FeatureResolve($directory))->__invoke();
     $output->writeln("\nFinding files on <info>" . $directory . "</info>\n");
     $tagFormatter = new Tags();
     $featureDescription = new FeatureDescription();
     $background = new Background($align);
     $scenario = new Scenario($align);
     /* @var $file \Symfony\Component\Finder\SplFileInfo */
     foreach ($finder as $file) {
         $fileContent = $file->getContents();
         $contentWithoutComments = $this->removeComments($fileContent);
         $feature = $this->parser->parse($fileContent);
         $formatted = $feature->hasTags() ? $tagFormatter->format($feature->getTags()) . "\n" : '';
         $formatted .= $featureDescription->format($feature) . "\n\n";
         $formatted .= $feature->hasBackground() ? $background->format($feature->getBackground()) . "\n" : '';
         $formatted .= $feature->hasScenarios() ? $scenario->format($feature->getScenarios()) : '';
         if ($formatted !== $contentWithoutComments) {
             if (!defined('FAILED')) {
                 define('FAILED', true);
             }
             $diff = new Differ("--- Original\n+++ Expected\n", false);
             $output->writeln('<error>Wrong style: ' . $file->getRealPath() . '</error>');
             $output->writeln($diff->diff($contentWithoutComments, $formatted));
         }
     }
     if (defined('FAILED')) {
         return 1;
     }
     $output->writeln('<bg=green;fg=white>     Everything is OK!     </>');
 }