From 052629ff7ddbbfd88751e0dff558baddabf6e248 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 1 May 2019 19:02:49 +0100 Subject: [PATCH] Generated output filenames should match the input filename --- src/Console/Command/GenerateCommand.php | 7 +++-- .../Console/Command/GenerateFiltersTest.php | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Console/Command/GenerateCommand.php b/src/Console/Command/GenerateCommand.php index 40af0e6..02969d5 100644 --- a/src/Console/Command/GenerateCommand.php +++ b/src/Console/Command/GenerateCommand.php @@ -24,7 +24,7 @@ class GenerateCommand extends Command ->setName(self::NAME) ->setDefinition([ new InputOption('input-file', 'i', InputOption::VALUE_OPTIONAL, 'The name of the PHP file containing your filters.', 'filters.php'), - new InputOption('output-file', 'o', InputOption::VALUE_OPTIONAL, 'The name of the XML file to generate.', 'filters.xml'), + new InputOption('output-file', 'o', InputOption::VALUE_OPTIONAL, 'The name of the XML file to generate.'), new InputOption('expanded', 'e', InputOption::VALUE_NONE, 'Whether to generate expanded XML.') ]) ->setDescription('Generates XML for Gmail filters.') @@ -50,7 +50,10 @@ class GenerateCommand extends Command private function outputFile(InputInterface $input): string { - return $input->getOption('output-file') ?? getcwd() . '/filters.xml'; + return $input->getOption('output-file') ?? vsprintf('%s/%s.xml', [ + getcwd(), + pathinfo($input->getOption('input-file'))['filename'], + ]); } private function filters(InputInterface $input): array diff --git a/tests/Unit/Console/Command/GenerateFiltersTest.php b/tests/Unit/Console/Command/GenerateFiltersTest.php index 59bca9f..84da4aa 100644 --- a/tests/Unit/Console/Command/GenerateFiltersTest.php +++ b/tests/Unit/Console/Command/GenerateFiltersTest.php @@ -33,6 +33,33 @@ class GenerateFiltersTest extends TestCase $this->fs->remove([self::OUTPUT_FILENAME]); } + /** @test */ + public function the_output_filename_matches_the_input_name() + { + $this->commandTester->execute([ + '--input-file' => self::INPUT_FILENAME, + ]); + + $this->assertTrue($this->fs->exists('input.xml')); + + $this->fs->remove('input.xml'); + } + + /** @test */ + public function the_output_filename_can_be_set_explicity() + { + $outputFilename = 'a-different-filename.xml'; + + $this->commandTester->execute([ + '--input-file' => self::INPUT_FILENAME, + '--output-file' => $outputFilename, + ]); + + $this->assertTrue($this->fs->exists($outputFilename)); + + $this->fs->remove($outputFilename); + } + /** @test */ public function it_converts_filters_from_php_to_minified_xml() {