A filter group contains the correct number of filters

This commit is contained in:
Oliver Davies 2019-04-01 18:18:33 +01:00
parent 7cabd2fb2f
commit af985e8b37
2 changed files with 68 additions and 0 deletions

37
src/Model/FilterGroup.php Normal file
View file

@ -0,0 +1,37 @@
<?php
namespace Opdavies\GmailFilterBuilder\Model;
use Tightenco\Collect\Support\Collection;
class FilterGroup
{
/** @var Collection */
private $filters;
public function __construct()
{
$this->filters = new Collection();
}
public static function if(Filter $filter): self
{
$self = new static();
$self->filters->push($filter);
return $self;
}
public function otherwise(Filter $filter): self
{
$this->filters->push($filter);
return $this;
}
public function toArray(): array
{
return $this->filters->toArray();
}
}

31
tests/OtherwiseTest.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace Tests\Opdavies\GmailFilterBuilder;
use Opdavies\GmailFilterBuilder\Model\Filter;
use Opdavies\GmailFilterBuilder\Model\FilterGroup;
use PHPUnit\Framework\TestCase;
class OtherwiseTest extends TestCase
{
/** @test */
public function it_returns_the_correct_number_of_filters()
{
$filters = FilterGroup::if(
Filter::create()
->has('to:me@example.com foo')
->labelAndArchive('Test')
)->otherwise(
Filter::create()
->has('to:me@example.com bar')
->read()
)->otherwise(
Filter::create()
->has('to:me@example.com')
->trash()
);
$this->assertCount(3, $filters->toArray());
}
}