Split and store the conditions for a filter

This commit is contained in:
Oliver Davies 2019-04-01 23:23:52 +01:00
parent af985e8b37
commit 1578cc81a3
2 changed files with 29 additions and 0 deletions

View file

@ -2,6 +2,8 @@
namespace Opdavies\GmailFilterBuilder\Model;
use Tightenco\Collect\Support\Collection;
class Filter
{
/**
@ -9,6 +11,14 @@ class Filter
*/
private $properties = [];
/** @var Collection */
private $conditions;
public function __construct()
{
$this->conditions = new Collection();
}
/**
* @return static
*/
@ -26,6 +36,10 @@ class Filter
{
$this->properties['hasTheWord'] = $value;
$this->conditions = $this->conditions->merge(
new Collection(preg_split('/\s+/', $value))
);
return $this;
}
@ -271,4 +285,9 @@ class Filter
{
return $this->properties;
}
public function getConditions(): Collection
{
return $this->conditions;
}
}

View file

@ -320,4 +320,14 @@ class FilterTest extends TestCase
->toArray()
);
}
/** @test */
public function conditions_can_be_split_and_stored()
{
$filter = Filter::create()
->has('to:me@example.com subject:Something')
->archive();
$this->assertCount(2, $filter->getConditions());
}
}