From af985e8b37d11be969ee26805f34515261ec401f Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 1 Apr 2019 18:18:33 +0100 Subject: [PATCH] A filter group contains the correct number of filters --- src/Model/FilterGroup.php | 37 +++++++++++++++++++++++++++++++++++++ tests/OtherwiseTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/Model/FilterGroup.php create mode 100644 tests/OtherwiseTest.php diff --git a/src/Model/FilterGroup.php b/src/Model/FilterGroup.php new file mode 100644 index 0000000..6f40ebb --- /dev/null +++ b/src/Model/FilterGroup.php @@ -0,0 +1,37 @@ +filters = new Collection(); + } + + public static function if(Filter $filter): self + { + $self = new static(); + + $self->filters->push($filter); + + return $self; + } + + public function otherwise(Filter $filter): self + { + $this->filters->push($filter); + + return $this; + } + + public function toArray(): array + { + return $this->filters->toArray(); + } +} diff --git a/tests/OtherwiseTest.php b/tests/OtherwiseTest.php new file mode 100644 index 0000000..238bbc0 --- /dev/null +++ b/tests/OtherwiseTest.php @@ -0,0 +1,31 @@ +has('to:me@example.com foo') + ->labelAndArchive('Test') + )->otherwise( + Filter::create() + ->has('to:me@example.com bar') + ->read() + )->otherwise( + Filter::create() + ->has('to:me@example.com') + ->trash() + ); + + $this->assertCount(3, $filters->toArray()); + } +}