Add GenerateFiltersTest

This commit is contained in:
Oliver Davies 2019-04-18 21:08:19 +01:00
parent a4c913ab38
commit 0346f25f96
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,51 @@
<?php
namespace Opdavies\Tests\GmailFilterBuilder\Console\Command;
use Opdavies\GmailFilterBuilder\Console\Command\GenerateCommand;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
class GenerateFiltersTest extends TestCase
{
const INPUT_FILENAME = __DIR__ . '/../../../fixtures/simple/input.php';
const OUTPUT_FILENAME = 'test-output.xml';
/** @var CommandTester */
private $commandTester;
/** @var Filesystem */
private $fs;
protected function setUp()
{
parent::setUp();
$this->commandTester = new CommandTester(new GenerateCommand());
$this->fs = new Filesystem();
}
protected function tearDown()
{
// Ensure that files generated during tests are removed to prevent
// failures on future runs.
$this->fs->remove([self::OUTPUT_FILENAME]);
}
/** @test */
public function it_converts_filters_from_php_to_xml()
{
$this->commandTester->execute([
'--input-file' => self::INPUT_FILENAME,
'--output-file' => self::OUTPUT_FILENAME,
]);
$this->assertTrue($this->fs->exists(self::OUTPUT_FILENAME));
$expected = file_get_contents(__DIR__ . '/../../../fixtures/simple/output.xml');
$result = file_get_contents(self::OUTPUT_FILENAME);
$this->assertEquals(trim($expected), $result);
}
}

9
tests/fixtures/simple/input.php vendored Normal file
View file

@ -0,0 +1,9 @@
<?php
use Opdavies\GmailFilterBuilder\Model\Filter;
return [
Filter::create()
->from('example.com')
->labelAndArchive('Test'),
];