48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Filter;
|
||
|
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
use TypeError;
|
||
|
|
||
|
/**
|
||
|
* @covers \Filter\FilterParser
|
||
|
*/
|
||
|
class FilterParserTest extends TestCase
|
||
|
{
|
||
|
private FilterParser $parser;
|
||
|
|
||
|
protected function setUp(): void
|
||
|
{
|
||
|
$this->parser = new FilterParser();
|
||
|
}
|
||
|
|
||
|
public function testCreatesSpecificFilters(): void
|
||
|
{
|
||
|
self::assertContainsOnlyInstancesOf(SpecificFilter::class, [
|
||
|
$this->parser->parse('title=poo'),
|
||
|
$this->parser->parse('1='),
|
||
|
$this->parser->parse('filepath=some_thing_else'),
|
||
|
]);
|
||
|
|
||
|
self::assertNotInstanceOf(SpecificFilter::class, $this->parser->parse('='));
|
||
|
}
|
||
|
|
||
|
public function testCreatesGenericFilters(): void
|
||
|
{
|
||
|
// Basically, anything that does not match the pattern .+=.*
|
||
|
self::assertContainsOnlyInstancesOf(GenericFilter::class, [
|
||
|
$this->parser->parse('scoobypoo'),
|
||
|
$this->parser->parse('324234'),
|
||
|
$this->parser->parse(324234),
|
||
|
$this->parser->parse('baz'),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
public function testDoesNotTakeNull(): void
|
||
|
{
|
||
|
$this->expectException(TypeError::class);
|
||
|
$this->parser->parse(null);
|
||
|
}
|
||
|
}
|