diff --git a/src/Model/Filter.php b/src/Model/Filter.php index 75d036f..424b7ee 100644 --- a/src/Model/Filter.php +++ b/src/Model/Filter.php @@ -48,9 +48,11 @@ class Filter */ public function from($values) { - $this->properties['from'] = collect($values)->map(function ($value) { - return trim($value); - })->all(); + if (!empty($values)) { + $this->properties['from'] = collect($values)->map(function ($value) { + return trim($value); + })->all(); + } return $this; } @@ -62,9 +64,11 @@ class Filter */ public function to($values) { - $this->properties['to'] = collect($values)->map(function ($value) { - return trim($value); - })->all(); + if (!empty($values)) { + $this->properties['to'] = collect($values)->map(function ($value) { + return trim($value); + })->all(); + } return $this; } diff --git a/tests/Unit/FilterTest.php b/tests/Unit/FilterTest.php index aaded0c..ca3c3c1 100644 --- a/tests/Unit/FilterTest.php +++ b/tests/Unit/FilterTest.php @@ -58,6 +58,18 @@ class FilterTest extends TestCase ['from' => ['foo@example.com', 'bar@example.com']], $this->filter->from(['foo@example.com', 'bar@example.com'])->getProperties() ); + + } + + /** + * Test that no 'from' key exists if no values were entered. + * + * @covers Filter::from() + */ + public function testNoFromPropertyExistsIfTheValueIsEmpty() + { + $this->assertArrayNotHasKey('from', $this->filter->from('')->getProperties()); + $this->assertArrayNotHasKey('from', $this->filter->from([])->getProperties()); } /** @@ -76,6 +88,15 @@ class FilterTest extends TestCase ); } + /** + * Test that no 'to' key exists if values were entered. + */ + public function testNoToPropertyExistsIfTheValueIsEmpty() + { + $this->assertArrayNotHasKey('to', $this->filter->to('')->getProperties()); + $this->assertArrayNotHasKey('to', $this->filter->to([])->getProperties()); + } + /** * @covers Filter::subject() */