/** * 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); }
public function testApplyMutators() { $target = new stdClass(); $mutator = Mockery::mock('Ve\\LogicProcessor\\AbstractResult'); $mutator->shouldReceive('mutate')->with($target)->once(); $this->set->addResult($mutator); $this->set->applyResults($target); }
/** * Builds a full rule set with a rule and results. * * @param array $data * * @return RuleSet */ public function buildRuleSet($data) { $ruleSet = new RuleSet(); if (isset($data['identifier'])) { $ruleSet->setIdentifier($data['identifier']); } // Build the rule if (isset($data['rule'])) { $ruleSet->setRule($this->buildRule($data['rule'])); } // Loop over each result and build that too if (isset($data['result'])) { foreach ($data['result'] as $result) { $ruleSet->addResult($this->buildResult($result)); } } return $ruleSet; }