mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-01-22 20:17:31 +00:00
A filter group contains the correct number of filters
This commit is contained in:
parent
7cabd2fb2f
commit
af985e8b37
37
src/Model/FilterGroup.php
Normal file
37
src/Model/FilterGroup.php
Normal 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
31
tests/OtherwiseTest.php
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue