mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-01-22 12:07:32 +00:00
Add GenerateFiltersTest
This commit is contained in:
parent
a4c913ab38
commit
0346f25f96
51
tests/Unit/Console/Command/GenerateFiltersTest.php
Normal file
51
tests/Unit/Console/Command/GenerateFiltersTest.php
Normal 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
9
tests/fixtures/simple/input.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
use Opdavies\GmailFilterBuilder\Model\Filter;
|
||||
|
||||
return [
|
||||
Filter::create()
|
||||
->from('example.com')
|
||||
->labelAndArchive('Test'),
|
||||
];
|
Loading…
Reference in a new issue