Esempio n. 1
0
 public function case_new_operators()
 {
     $this->given($user = new \Mock\StdClass(), $user->group = 'customer', $user->points = 42, $user->status = true, $ruler = new LUT(), $rule = 'logged(user) and group in ["customer", "guest"] and points > 30', $context = new LUT\Context(), $context['user'] = function () use($user, $context) {
         $context['group'] = $user->group;
         $context['points'] = $user->points;
         return $user;
     })->when($ruler->getDefaultAsserter()->setOperator('logged', function ($user) {
         return $user->status;
     }), $result = $ruler->assert($rule, $context))->then->boolean($result)->isTrue()->given($user->status = false)->when($result = $ruler->assert($rule, $context))->then->boolean($result)->isFalse();
 }
Esempio n. 2
0
 public function case_lazy_or()
 {
     $this->given($ruler = new LUT(), $fExecuted = false, $gExecuted = false, $asserter = $ruler->getDefaultAsserter(), $asserter->setOperator('f', function ($a) use(&$fExecuted) {
         $fExecuted = true;
         return $a;
     }), $asserter->setOperator('g', function ($b) use(&$gExecuted) {
         $gExecuted = true;
         return $b;
     }), $rule = 'f(false) or g(true)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isTrue()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isTrue()->given($fExecuted = false, $gExecuted = false, $rule = 'f(true) or g(true)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isTrue()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isFalse()->given($fExecuted = false, $gExecuted = false, $rule = 'f(true) or g(false)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isTrue()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isFalse()->given($fExecuted = false, $gExecuted = false, $rule = 'f(false) or g(false)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isFalse()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isTrue();
 }