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')); + }); } }