public function testRuleCreation()
 {
     $rb = new RuleBuilder();
     $context = new Context();
     $true = new TrueProposition();
     $false = new FalseProposition();
     $this->assertInstanceOf('Ruler\\Rule', $rb->create($true));
     $this->assertTrue($rb->create($true)->evaluate($context));
     $this->assertFalse($rb->create($false)->evaluate($context));
     $executed = false;
     $rule = $rb->create($true, function () use(&$executed) {
         $executed = true;
     });
     $this->assertFalse($executed);
     $rule->execute($context);
     $this->assertTrue($executed);
 }
Exemple #2
0
 public function test_featureWithRuleBuilder()
 {
     $rb = new RuleBuilder();
     $rule = $rb->create($rb['admin.users']->setContains($rb['username']));
     $feature = new Feature('test.feature', $rule);
     $context = new Context(array('admin.users' => array('joshua'), 'username' => 'joshua'));
     $feature->setContext($context);
     $this->assertTrue($feature->isEnabled());
     $rb = new RuleBuilder();
     $rb->registerOperatorNamespace('Dspacelabs\\Component\\Feature\\Operator');
     $feature = new Feature('test.feature', $rb['always']->enabled());
     $this->assertTrue($feature->isEnabled());
     $rb = new RuleBuilder();
     $rb->registerOperatorNamespace('Dspacelabs\\Component\\Feature\\Operator');
     $feature = new Feature('test.feature', $rb['always']->disabled());
     $this->assertTrue($feature->isDisabled());
     $rb = new RuleBuilder();
     $feature = new Feature('test.feature', $rb['username']->equalTo('joshua'));
     $this->assertTrue($feature->isDisabled());
     $feature->setContext(new Context(array('username' => 'joshua')));
     $this->assertTrue($feature->isEnabled());
 }
Exemple #3
0
 /**
  * @dataProvider truthTableOne
  */
 public function testNonContradiction($p)
 {
     $rb = new RuleBuilder();
     $context = new Context(compact('p'));
     $this->assertEquals($rb->create($rb->logicalNot($rb->logicalAnd($rb['p']->equalTo(true), $rb->logicalNot($rb['p']->equalTo(true)))))->evaluate($context), true);
 }
Exemple #4
0
 /**
  * @dataProvider setSymmetricDifference
  */
 public function testSymmetricDifference($a, $b, $expected)
 {
     $rb = new RuleBuilder();
     $context = new Context(compact('a', 'b', 'expected'));
     $this->assertTrue($rb->create($rb['expected']->equalTo($rb['a']->symmetricDifference($rb['b'])))->evaluate($context));
 }