/**
  * {@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!     </>');
 }
    public function testCanFormatFeatureDescription()
    {
        $expected = <<<EOS
Feature: How to be a kawai person
    In order to be a kawai person
    As a non-kawai person
    I have to turn me a PHP programmer
EOS;
        $shortDescription = 'How to be a kawai person';
        $longDescription = ['           In order to be a kawai person', 'As a non-kawai person                  ', '                   I have to turn me a PHP programmer'];
        self::assertSame($expected, $this->formatter->format($shortDescription, $longDescription));
    }
    public function testCanFormatFeatureDescription()
    {
        $expected = <<<EOS
Feature: How to be a kawai person
    In order to be a kawai person
    As a non-kawai person
    I have to turn me a PHP programmer
EOS;
        $shortDescription = 'How to be a kawai person';
        $longDescription = ['           In order to be a kawai person', 'As a non-kawai person                  ', '                   I have to turn me a PHP programmer'];
        $feature = new FeatureNode($shortDescription, implode("\n", $longDescription), [], null, [], 'Feature', 'en', '/tmp.feature', 12);
        self::assertSame($expected, $this->formatter->format($feature));
    }
 /**
  * {@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>');
     }
 }