/** * 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)); }
/** * 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; })]; }