respect-validation/tests/unit/Rules/NotTest.php

92 lines
2.5 KiB
PHP
Raw Normal View History

<?php
2015-06-08 16:47:14 +02:00
/*
* 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;
2017-11-04 11:21:40 +01:00
use PHPUnit\Framework\TestCase;
2012-05-17 21:16:45 +02:00
use Respect\Validation\Validator;
/**
* @group rule
2017-02-04 14:01:14 +01:00
* @covers \Respect\Validation\Rules\Not
* @covers \Respect\Validation\Exceptions\NotException
*/
2017-11-04 11:21:40 +01:00
class NotTest extends TestCase
{
/**
* @dataProvider providerForValidNot
*/
public function testNot($v, $input): void
{
$not = new Not($v);
self::assertTrue($not->assert($input));
}
/**
* @dataProvider providerForInvalidNot
2017-02-04 14:01:14 +01:00
* @expectedException \Respect\Validation\Exceptions\ValidationException
*/
public function testNotNotHaha($v, $input): void
{
$not = new Not($v);
self::assertFalse($not->assert($input));
}
2016-01-29 22:50:27 +01:00
/**
* @dataProvider providerForSetName
*/
public function testNotSetName($v): void
2016-01-29 22:50:27 +01:00
{
$not = new Not($v);
$not->setName('Foo');
self::assertEquals('Foo', $not->getName());
self::assertEquals('Foo', $v->getName());
2016-01-29 22:50:27 +01:00
}
public function providerForValidNot()
{
2015-10-18 03:44:47 +02:00
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'],
2016-11-06 18:45:44 +01:00
[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],
2015-10-18 03:44:47 +02:00
];
}
public function providerForInvalidNot()
{
2015-10-18 03:44:47 +02:00
return [
[new IntVal(), 123],
2017-02-05 12:23:22 +01:00
[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],
2015-10-18 03:44:47 +02:00
];
}
2016-01-29 22:50:27 +01:00
public function providerForSetName()
{
return [
[new IntVal()],
2016-11-06 18:45:44 +01:00
[new AllOf(new NumericVal(), new IntVal())],
2016-01-29 22:50:27 +01:00
[new Not(new Not(new IntVal()))],
[Validator::intVal()->setName('Bar')],
2016-11-06 18:45:44 +01:00
[Validator::noneOf(Validator::numericVal(), Validator::intVal())],
2016-01-29 22:50:27 +01:00
];
}
2012-05-17 20:51:49 +02:00
}