mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-09-06 05:25:33 +01:00
Fix output for tests to pass again
This commit is contained in:
parent
6d6f5596ce
commit
b9b41aa437
3 changed files with 37 additions and 9 deletions
|
@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
|
||||
class GenerateCommand extends Command
|
||||
{
|
||||
|
@ -44,10 +45,14 @@ class GenerateCommand extends Command
|
|||
throw new \Exception('No filters.php file found.');
|
||||
}
|
||||
|
||||
// TOOD: Check return code.
|
||||
new Builder($filters, $outputFile);
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->success(sprintf('%s file generated.', $outputFile));
|
||||
|
||||
try {
|
||||
new Builder($filters, $outputFile);
|
||||
|
||||
$io->success(sprintf('%s file generated.', $outputFile));
|
||||
} catch (IOException $e) {
|
||||
$io->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,21 @@ class Builder
|
|||
*/
|
||||
private $outputFile;
|
||||
|
||||
public function __construct(array $filters, $outputFile = 'filters.xml') {
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $writeFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $xml;
|
||||
|
||||
public function __construct(array $filters, $outputFile = 'filters.xml', $writeFile = true) {
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->filters = $filters;
|
||||
$this->outputFile = $outputFile;
|
||||
$this->writeFile = $writeFile;
|
||||
|
||||
$this->build();
|
||||
}
|
||||
|
@ -32,6 +43,16 @@ class Builder
|
|||
return $this->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the generated XML.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getXml()
|
||||
{
|
||||
return $this->xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build XML for a set of filters.
|
||||
*
|
||||
|
@ -46,9 +67,11 @@ class Builder
|
|||
return $this->buildEntry($items);
|
||||
})->implode(PHP_EOL);
|
||||
|
||||
$content = collect([$prefix, $xml, $suffix])->implode(PHP_EOL);
|
||||
$this->xml = collect([$prefix, $xml, $suffix])->implode(PHP_EOL);
|
||||
|
||||
$this->filesystem->dumpFile($this->outputFile, $content);
|
||||
if ($this->writeFile) {
|
||||
$this->filesystem->dumpFile($this->outputFile, $this->xml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue