diff --git a/src/Model/FilterGroup.php b/src/Model/FilterGroup.php index ffcf12b..e33a6e9 100644 --- a/src/Model/FilterGroup.php +++ b/src/Model/FilterGroup.php @@ -39,4 +39,9 @@ class FilterGroup { return $this->filters; } + + public function getConditions(): Collection + { + return $this->filters->map->getConditions(); + } } diff --git a/tests/OtherwiseHasTest.php b/tests/OtherwiseHasTest.php index dc147a8..53c7847 100644 --- a/tests/OtherwiseHasTest.php +++ b/tests/OtherwiseHasTest.php @@ -5,6 +5,7 @@ namespace Tests\Opdavies\GmailFilterBuilder; use Opdavies\GmailFilterBuilder\Model\Filter; use Opdavies\GmailFilterBuilder\Model\FilterGroup; use PHPUnit\Framework\TestCase; +use Tightenco\Collect\Support\Collection; class OtherwiseHasTest extends TestCase { @@ -47,6 +48,34 @@ class OtherwiseHasTest extends TestCase }); } + /** @test */ + public function get_all_conditions_from_a_filter_group() + { + $filters = FilterGroup::if( + Filter::create() + ->has('to:me@example.com subject:Foo') + ->read() + )->otherwise( + Filter::create() + ->has('to:me@example.com subject:Bar') + ->trash() + )->otherwise( + Filter::create() + ->has('to:me@example.com subject:Baz') + ->trash() + ); + + $expected = [ + ['to:me@example.com', 'subject:Foo'], + ['to:me@example.com', 'subject:Bar'], + ['to:me@example.com', 'subject:Baz'], + ]; + + $conditions = $filters->getConditions(); + $this->assertInstanceOf(Collection::class, $conditions); + $this->assertSame($expected, $conditions->toArray()); + } + /** @test */ public function different_conditions_are_negated_in_subsequent_filters() {