Generated output filenames should match the input filename

This commit is contained in:
Oliver Davies 2019-05-01 19:02:49 +01:00
parent 2e8e58abd0
commit 052629ff7d
2 changed files with 32 additions and 2 deletions

View file

@ -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

View file

@ -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()
{