* * For the full copyright and license information, please view the "LICENSE.md" * file that was distributed with this source code. */ namespace Respect\Validation\Rules; use PHPUnit\Framework\TestCase; use Respect\Validation\Validator; /** * @group rule * @covers \Respect\Validation\Rules\Not * @covers \Respect\Validation\Exceptions\NotException */ class NotTest extends TestCase { /** * @dataProvider providerForValidNot */ public function testNot($v, $input) { $not = new Not($v); $this->assertTrue($not->assert($input)); } /** * @dataProvider providerForInvalidNot * @expectedException \Respect\Validation\Exceptions\ValidationException */ public function testNotNotHaha($v, $input) { $not = new Not($v); $this->assertFalse($not->assert($input)); } /** * @dataProvider providerForSetName */ public function testNotSetName($v) { $not = new Not($v); $not->setName('Foo'); $this->assertEquals('Foo', $not->getName()); $this->assertEquals('Foo', $v->getName()); } public function providerForValidNot() { return [ [new IntVal(), ''], [new IntVal(), 'aaa'], [new AllOf(new NoWhitespace(), new Digit()), 'as df'], [new AllOf(new NoWhitespace(), new Digit()), '12 34'], [new AllOf(new AllOf(new NoWhitespace(), new Digit())), '12 34'], [new AllOf(new NoneOf(new NumericVal(), new IntVal())), 13.37], [new NoneOf(new NumericVal(), new IntVal()), 13.37], [Validator::noneOf(Validator::numericVal(), Validator::intVal()), 13.37], ]; } public function providerForInvalidNot() { return [ [new IntVal(), 123], [new AllOf(new AnyOf(new NumericVal(), new IntVal())), 13.37], [new AnyOf(new NumericVal(), new IntVal()), 13.37], [Validator::anyOf(Validator::numericVal(), Validator::intVal()), 13.37], ]; } public function providerForSetName() { return [ [new IntVal()], [new AllOf(new NumericVal(), new IntVal())], [new Not(new Not(new IntVal()))], [Validator::intVal()->setName('Bar')], [Validator::noneOf(Validator::numericVal(), Validator::intVal())], ]; } }