From 654457beee6c29e6a61401c1d1841180ec74bd98 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 4 Nov 2017 09:20:46 +0000 Subject: [PATCH] Add more conditions --- src/Filter.php | 40 ++++++++++++++++++++++- tests/Unit/FilterTest.php | 67 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index 4e77b2e..3380eee 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -13,12 +13,50 @@ class Filter return $this; } + public function hasNot($value) + { + $this->properties['doesNotHaveTheWord'] = $value; + + return $this; + } + public function from() { $this->properties['from'] = collect(func_get_args()) ->map(function ($address) { return trim($address); - })->implode(','); + })->all(); + + return $this; + } + + public function to() + { + $this->properties['to'] = collect(func_get_args()) + ->map(function ($address) { + return trim($address); + })->all(); + + return $this; + } + + public function subject($subject) + { + $this->properties['subject'] = $subject; + + return $this; + } + + public function hasAttachment() + { + $this->properties['hasAttachment'] = 'true'; + + return $this; + } + + public function excludeChats() + { + $this->properties['excludeChats'] = 'true'; return $this; } diff --git a/tests/Unit/FilterTest.php b/tests/Unit/FilterTest.php index 031dc71..f9e9ee7 100644 --- a/tests/Unit/FilterTest.php +++ b/tests/Unit/FilterTest.php @@ -32,6 +32,16 @@ class FilterTest extends \PHPUnit_Framework_TestCase ); } + /** + * @covers Filter::hasNot() + */ + public function testHasNot() { + $this->assertEquals( + ['doesNotHaveTheWord' => 'something'], + $this->filter->hasNot('something')->getProperties() + ); + } + /** * @covers Filter::from() */ @@ -39,19 +49,65 @@ class FilterTest extends \PHPUnit_Framework_TestCase { // Ensure that we can set one from address. $this->assertEquals( - ['from' => 'foo@example.com'], + ['from' => ['foo@example.com']], $this->filter->from('foo@example.com')->getProperties() ); // Ensure that we can set multiple from addresses. $this->assertEquals( - ['from' => 'foo@example.com,bar@example.com'], + ['from' => ['foo@example.com', 'bar@example.com']], $this->filter ->from('foo@example.com', 'bar@example.com') ->getProperties() ); } + /** + * @covers Filter::to() + */ + public function testTo() + { + $this->assertEquals( + ['to' => ['foo@example.com']], + $this->filter->to('foo@example.com')->getProperties() + ); + + $this->assertEquals( + ['to' => ['bar@example.com', 'baz@example.com']], + $this->filter->to('bar@example.com', 'baz@example.com') + ->getProperties() + ); + } + + /** + * @covers Filter::subject() + */ + public function testSubject() + { + $this->assertEquals( + ['subject' => 'Something'], + $this->filter->subject('Something')->getProperties() + ); + } + + /** + * @covers Filter::hasAttachment() + */ + public function testHasAttachment() + { + $this->assertEquals( + ['hasAttachment' => 'true'], + $this->filter->hasAttachment()->getProperties() + ); + } + + public function testExcludeChats() + { + $this->assertEquals( + ['excludeChats' => 'true'], + $this->filter->excludeChats()->getProperties() + ); + } /** * @covers Filter::label() */ @@ -171,24 +227,27 @@ class FilterTest extends \PHPUnit_Framework_TestCase ); } - public function testMethodsCanBeChained() { $this->assertEquals( [ - 'from' => 'foo@example.com,bar@example.com', + 'from' => ['foo@example.com', 'bar@example.com'], 'hasTheWord' => 'Something', + 'excludeChats' => 'true', 'label' => 'Foo', 'markAsRead' => 'true', 'shouldArchive' => 'true', 'shouldNeverSpam' => 'true', 'shouldSpam' => 'false', 'shouldStar' => 'true', + 'shouldAlwaysMarkAsImportant' => 'true', ], $this->filter->from('foo@example.com ', 'bar@example.com') ->has('Something') + ->excludeChats() ->labelAndArchive('Foo') ->read() + ->important() ->neverSpam() ->star() ->getProperties()