public function testTheAndLogicalValidatorReturnsExpectedResponse() { $test = new LAnd($this->true, $this->true); $this->assertTrue($test->isValid('foo')); $test = new LAnd($this->true, $this->false); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, $this->true); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, $this->false); $this->assertFalse($test->isValid('foo')); }
/** * @inheritDoc */ protected function validateArguments(array $args) { $valA1 = new HasTypeMap(['size' => 'integer']); $valA2 = new Lambda(function ($args) { return $args['size'] > 0; }, new StringType(self::ERR1)); $validator = new LAnd($valA1, $valA2); if (!$validator->isValid($args)) { throw new InvalidParameterException(implode(':', $validator->getMessages())); } }
/** * @inheritDoc */ protected function validateArguments(array $args) { $valA1 = new HasTypeMap(['rows' => 'integer', 'cols' => 'integer', 'f' => function ($val) { return $val instanceof \Closure; }]); $valA2 = new Lambda(function ($args) { return $args['rows'] > 0 && $args['cols'] > 0; }, new StringType(self::ERR1)); $validator = new LAnd($valA1, $valA2); if (!$validator->isValid($args)) { throw new InvalidParameterException(implode(':', $validator->getMessages())); } }
public function testCombinationsOfTheLogicalValidatorsWorkCorrectly() { //a AND (b OR c) $test = new LAnd($this->true, new LOr($this->true, $this->false)); $this->assertTrue($test->isValid('foo')); $test = new LAnd($this->true, new LOr($this->false, $this->true)); $this->assertTrue($test->isValid('foo')); $test = new LAnd($this->true, new LOr($this->true, $this->true)); $this->assertTrue($test->isValid('foo')); $test = new LAnd($this->true, new LOr($this->false, $this->false)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LOr($this->true, $this->false)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LOr($this->false, $this->true)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LOr($this->true, $this->true)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LOr($this->false, $this->false)); $this->assertFalse($test->isValid('foo')); //(a AND b) OR c $test = new Lor(new LAnd($this->true, $this->true), $this->true); $this->assertTrue($test->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->true), $this->true); $this->assertTrue($test->isValid('foo')); $test = new Lor(new LAnd($this->true, $this->false), $this->true); $this->assertTrue($test->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->false), $this->true); $this->assertTrue($test->isValid('foo')); $test = new Lor(new LAnd($this->true, $this->true), $this->false); $this->assertTrue($test->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->true), $this->false); $this->assertFalse($test->isValid('foo')); $test = new Lor(new LAnd($this->true, $this->false), $this->false); $this->assertFalse($test->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->false), $this->false); $this->assertFalse($test->isValid('foo')); //a AND (b XOR c) $test = new LAnd($this->true, new LXor($this->true, $this->false)); $this->assertTrue($test->isValid('foo')); $test = new LAnd($this->true, new LXor($this->false, $this->true)); $this->assertTrue($test->isValid('foo')); $test = new LAnd($this->true, new LXor($this->true, $this->true)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->true, new LXor($this->false, $this->false)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LXor($this->true, $this->false)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LXor($this->false, $this->true)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LXor($this->true, $this->true)); $this->assertFalse($test->isValid('foo')); $test = new LAnd($this->false, new LXor($this->false, $this->false)); $this->assertFalse($test->isValid('foo')); //(a AND b) XOR c $test = new LXor(new LAnd($this->true, $this->true), $this->true); $this->assertFalse($test->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->true), $this->true); $this->assertTrue($test->isValid('foo')); $test = new LXor(new LAnd($this->true, $this->false), $this->true); $this->assertTrue($test->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->false), $this->true); $this->assertTrue($test->isValid('foo')); $test = new LXor(new LAnd($this->true, $this->true), $this->false); $this->assertTrue($test->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->true), $this->false); $this->assertFalse($test->isValid('foo')); $test = new LXor(new LAnd($this->true, $this->false), $this->false); $this->assertFalse($test->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->false), $this->false); $this->assertFalse($test->isValid('foo')); //using not //NOT (a AND (b OR c)) $test = new LAnd($this->true, new LOr($this->true, $this->false)); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LAnd($this->true, new LOr($this->false, $this->true)); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LAnd($this->true, new LOr($this->true, $this->true)); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LAnd($this->true, new LOr($this->false, $this->false)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LOr($this->true, $this->false)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LOr($this->false, $this->true)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LOr($this->true, $this->true)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LOr($this->false, $this->false)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); //NOT ((a AND b) OR c) $test = new Lor(new LAnd($this->true, $this->true), $this->true); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->true), $this->true); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new Lor(new LAnd($this->true, $this->false), $this->true); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->false), $this->true); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new Lor(new LAnd($this->true, $this->true), $this->false); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->true), $this->false); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new Lor(new LAnd($this->true, $this->false), $this->false); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new Lor(new LAnd($this->false, $this->false), $this->false); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); //NOT (a AND (b XOR c)) $test = new LAnd($this->true, new LXor($this->true, $this->false)); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LAnd($this->true, new LXor($this->false, $this->true)); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LAnd($this->true, new LXor($this->true, $this->true)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->true, new LXor($this->false, $this->false)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LXor($this->true, $this->false)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LXor($this->false, $this->true)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LXor($this->true, $this->true)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LAnd($this->false, new LXor($this->false, $this->false)); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); //NOT ((a AND b) XOR c) $test = new LXor(new LAnd($this->true, $this->true), $this->true); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->true), $this->true); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LXor(new LAnd($this->true, $this->false), $this->true); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->false), $this->true); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LXor(new LAnd($this->true, $this->true), $this->false); $not = new LNot($test); $this->assertFalse($not->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->true), $this->false); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LXor(new LAnd($this->true, $this->false), $this->false); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); $test = new LXor(new LAnd($this->false, $this->false), $this->false); $not = new LNot($test); $this->assertTrue($not->isValid('foo')); //feel free to add other combinations if you are bored! }