From 954db7431d5840cca11b13bb2b26956c4553bce6 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Thu, 23 Jul 2020 23:26:10 +0200 Subject: [PATCH] [update] introduce addCondition method to CompoundCondition --- src/Model/Scope/CompoundCondition.php | 16 ++++++++++++++++ tests/ScopeTest.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Model/Scope/CompoundCondition.php b/src/Model/Scope/CompoundCondition.php index 5c550c352..bc3204dd4 100644 --- a/src/Model/Scope/CompoundCondition.php +++ b/src/Model/Scope/CompoundCondition.php @@ -68,6 +68,22 @@ public function __clone() } } + /** + * Add nested condition. + * + * @param mixed $field + * @param mixed $operator + * @param mixed $value + * + * @return static + */ + public function addCondition($field, $operator = null, $value = null) + { + $this->add(new self([func_get_args()])); + + return $this; + } + /** * Return array of nested conditions. * diff --git a/tests/ScopeTest.php b/tests/ScopeTest.php index b04cecf9f..4098e8392 100644 --- a/tests/ScopeTest.php +++ b/tests/ScopeTest.php @@ -298,9 +298,9 @@ public function testScope() $this->assertEquals($compoundCondition->toWords($user), $user->scope()->toWords()); - $condition5 = new BasicCondition('country_code', 'BR'); + $compoundCondition = CompoundCondition::createOr($compoundCondition1, $compoundCondition2); - $compoundCondition = CompoundCondition::createOr($compoundCondition1, $compoundCondition2, $condition5); + $compoundCondition->addCondition('country_code', 'BR'); $this->assertEquals('(Name is equal to \'John\' and Code is equal to \'CA\') or (Surname is equal to \'Doe\' and Code is equal to \'LV\') or Code is equal to \'BR\'', $compoundCondition->toWords($user));