respect-validation/tests/unit/Rules/NotTest.php
2018-12-05 08:57:05 +01:00

105 lines
2.8 KiB
PHP

<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\TestCase;
use Respect\Validation\Validator;
/**
* @group rule
* @covers \Respect\Validation\Exceptions\NotException
* @covers \Respect\Validation\Rules\Not
*
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
* @author Caio César Tavares <caiotava@gmail.com>
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
class NotTest extends TestCase
{
/**
* @doesNotPerformAssertions
*
* @dataProvider providerForValidNot
*
* @test
*/
public function not($v, $input): void
{
$not = new Not($v);
$not->assert($input);
}
/**
* @dataProvider providerForInvalidNot
* @expectedException \Respect\Validation\Exceptions\ValidationException
*
* @test
*/
public function notNotHaha($v, $input): void
{
$not = new Not($v);
$not->assert($input);
}
/**
* @dataProvider providerForSetName
*
* @test
*/
public function notSetName($v): void
{
$not = new Not($v);
$not->setName('Foo');
self::assertEquals('Foo', $not->getName());
self::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())],
];
}
}