Skip to content

Commit

Permalink
[update] introduce addCondition method to CompoundCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov committed Jul 23, 2020
1 parent 0b65f8e commit 954db74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/Model/Scope/CompoundCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 954db74

Please sign in to comment.