2011-04-28 01:41:12 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +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.
|
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2011-04-28 01:41:12 +02:00
|
|
|
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;
|
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
|
|
|
* @group rule
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Exceptions\NotException
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\Not
|
2018-11-25 17:56:04 +01:00
|
|
|
*
|
|
|
|
* @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>
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2017-11-04 11:21:40 +01:00
|
|
|
class NotTest extends TestCase
|
2011-04-28 01:41:12 +02:00
|
|
|
{
|
|
|
|
/**
|
2018-01-28 17:16:53 +01:00
|
|
|
* @doesNotPerformAssertions
|
|
|
|
*
|
2011-04-28 01:41:12 +02:00
|
|
|
* @dataProvider providerForValidNot
|
2018-07-23 20:35:14 +02:00
|
|
|
*
|
|
|
|
* @test
|
2011-04-28 01:41:12 +02:00
|
|
|
*/
|
2018-07-23 20:35:14 +02:00
|
|
|
public function not($v, $input): void
|
2011-04-28 01:41:12 +02:00
|
|
|
{
|
|
|
|
$not = new Not($v);
|
2018-01-28 17:16:53 +01:00
|
|
|
$not->assert($input);
|
2011-04-28 01:41:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalidNot
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
2018-07-23 20:35:14 +02:00
|
|
|
*
|
|
|
|
* @test
|
2011-04-28 01:41:12 +02:00
|
|
|
*/
|
2018-07-23 20:35:14 +02:00
|
|
|
public function notNotHaha($v, $input): void
|
2011-04-28 01:41:12 +02:00
|
|
|
{
|
|
|
|
$not = new Not($v);
|
2018-01-28 17:16:53 +01:00
|
|
|
$not->assert($input);
|
2011-04-28 01:41:12 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 22:50:27 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider providerForSetName
|
2018-07-23 20:35:14 +02:00
|
|
|
*
|
|
|
|
* @test
|
2016-01-29 22:50:27 +01:00
|
|
|
*/
|
2018-07-23 20:35:14 +02:00
|
|
|
public function notSetName($v): void
|
2016-01-29 22:50:27 +01:00
|
|
|
{
|
|
|
|
$not = new Not($v);
|
|
|
|
$not->setName('Foo');
|
|
|
|
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertEquals('Foo', $not->getName());
|
|
|
|
self::assertEquals('Foo', $v->getName());
|
2016-01-29 22:50:27 +01:00
|
|
|
}
|
|
|
|
|
2011-04-28 01:41:12 +02: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
|
|
|
];
|
2011-04-28 01:41:12 +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
|
|
|
];
|
2011-04-28 01:41:12 +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
|
|
|
}
|