/** * Performs an actual logical check without mocks as a form of integration test. */ protected function testFullRuleRun() { $set = new RuleSet(); // Set up and add a rule $rule = new HasProdRule(); $modifier = new Modifier\Equal(); $modifier->setTargetValue(10); $rule->setAssertion($modifier); $set->setRule($rule); // Set up and add a result $result = new OrderDiscountResult(); $result->setValue(10.0); $set->addResult($result); $context = ['products' => [['id' => 1, 'qty' => 10, 'price' => 10.0]]]; $target = new stdClass(); $target->total = 50.0; // Check the rule can be valid $this->processor->addRuleSet($rule); $this->processor->run($context, $target); $this->assertEquals(10.0, $target->total); // Check the rule can be false $target->total = 50.0; $context['products'][0]['qty'] = 5; $this->processor->run($context, $target); $this->assertEquals(50.0, $target->total); }
/** * Populates the given processor with the rule sets as outlined in the $data. * * @param array $data * @param Processor $processor * * @return Processor */ public function build($data, Processor $processor = null) { if ($processor === null) { $processor = new Processor(); } // Pull out the rule sets and build each one if (isset($data['rule_sets'])) { foreach ($data['rule_sets'] as $set) { $processor->addRuleSet($this->buildRuleSet($set)); } } return $processor; }