Exemplo n.º 1
0
 public function testContext()
 {
     $context = new base('ruletest');
     $this->string($context->getName())->isEqualTo('ruletest')->object($context->proposition('proposition 1', true))->isInstanceOf('MojoLyon\\Axiom\\Context')->object($context->variable('variable 1', 'valeur var 1'))->isInstanceOf('MojoLyon\\Axiom\\Context')->exception(function () use($context) {
         $context->operator('and');
     })->isInstanceOf('\\DomainException')->object($object1 = $context->findElement('proposition 1'))->isInstanceOf('MojoLyon\\Axiom\\RuleElement\\Proposition')->object($object2 = $context->findElement('variable 1'))->isInstanceOf('MojoLyon\\Axiom\\RuleElement\\Variable')->variable($context->findElement('notset'))->isNull()->string($object1->getName())->isEqualTo('proposition 1')->boolean($object1->getValue())->isTrue()->string($object2->getName())->isEqualTo('variable 1')->string($object2->getValue())->isEqualTo('valeur var 1');
 }
Exemplo n.º 2
0
 /**
  * Evaluate the rule
  *
  * Apply context values on rule elements then evaluate rule
  *
  * @param Context $context Context for rule evaluation
  *
  * @throws \UnexpectedValueException
  *
  * @return RuleElement\Proposition
  */
 public function evaluate(Context $context)
 {
     foreach ($this->elements as $rule) {
         if ($rule instanceof RuleElement\Operator) {
             continue;
         }
         $contextEl = $context->findElement($rule->getName());
         if ($contextEl === null) {
             continue;
         }
         if (!$rule instanceof $contextEl) {
             throw new \UnexpectedValueException("Context element type doesn't match rule element type ");
         }
         $rule->setValue($contextEl->getValue());
     }
     return $this->process();
 }