예제 #1
0
 /**
  * Evaluate compound rules.
  *
  * @dataProvider providerEvaluateCompoundRule
  *
  * @param int  $amount
  * @param int  $quantity
  * @param bool $expected
  */
 public function testEvaluateCompoundRule($amount, $quantity, $expected)
 {
     $rule = new Rule();
     $rule->setExpression('rule("cart_valuable_items")');
     $cart = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface');
     $cart->expects($this->any())->method('getAmount')->willReturn($amount);
     $cart->expects($this->any())->method('getQuantity')->willReturn($quantity);
     $context = ['cart' => $cart];
     $this->assertEquals($expected, $this->ruleManager->evaluate($rule, $context));
 }
예제 #2
0
 /**
  * Get functions
  *
  * @return ExpressionFunction[] An array of Function instances
  */
 public function getFunctions()
 {
     return [new ExpressionFunction('rule', function () {
         throw new RuntimeException('Function "rule" can\'t be compiled.');
     }, function (array $context, $value) {
         /**
          * @var Rule $rule
          */
         $rule = $this->ruleRepository->findOneBy(['name' => $value]);
         return $rule ? $this->ruleManager->evaluate($rule, $context) : false;
     })];
 }