From f70038235597f1d878fa84cc91d36c98a6746725 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 1 Apr 2019 23:26:00 +0100 Subject: [PATCH] Same conditions are kept within a filter group --- src/Model/FilterGroup.php | 9 +++++++-- tests/OtherwiseTest.php | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Model/FilterGroup.php b/src/Model/FilterGroup.php index 6f40ebb..ffcf12b 100644 --- a/src/Model/FilterGroup.php +++ b/src/Model/FilterGroup.php @@ -30,8 +30,13 @@ class FilterGroup return $this; } - public function toArray(): array + /** + * Get all filters within this filter group. + * + * @return Collection + */ + public function all(): Collection { - return $this->filters->toArray(); + return $this->filters; } } diff --git a/tests/OtherwiseTest.php b/tests/OtherwiseTest.php index 238bbc0..675f928 100644 --- a/tests/OtherwiseTest.php +++ b/tests/OtherwiseTest.php @@ -26,6 +26,24 @@ class OtherwiseTest extends TestCase ->trash() ); - $this->assertCount(3, $filters->toArray()); + $this->assertCount(3, $filters->all()); + } + + /** @test */ + public function same_conditions_are_kept_between_filters() + { + $filters = FilterGroup::if( + Filter::create() + ->has('to:me@example.com subject:Foo') + ->read() + )->otherwise( + Filter::create() + ->has('to:me@example.com subject:Bar') + ->trash() + ); + + $filters->all()->each(function (Filter $filter) { + $this->assertTrue($filter->getConditions()->contains('to:me@example.com')); + }); } }