mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-02-02 08:57:31 +00:00
Fix output for tests to pass again
This commit is contained in:
parent
6d6f5596ce
commit
b9b41aa437
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@ class BuilderTest extends TestCase
|
|||
->star()
|
||||
->important();
|
||||
|
||||
$result = new Builder([$filterA, $filterB]);
|
||||
$result = new Builder([$filterA, $filterB], '', false);
|
||||
|
||||
$expected = <<<EOF
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
|
@ -36,6 +36,6 @@ class BuilderTest extends TestCase
|
|||
</feed>
|
||||
EOF;
|
||||
|
||||
$this->assertEquals($expected, $result->__toString());
|
||||
$this->assertEquals($expected, $result->getXml());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue