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.
|
|
|
|
*/
|
|
|
|
|
2011-04-28 01:41:12 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
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\Rules\Not
|
|
|
|
* @covers \Respect\Validation\Exceptions\NotException
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2011-04-28 01:41:12 +02:00
|
|
|
class NotTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForValidNot
|
|
|
|
*/
|
|
|
|
public function testNot($v, $input)
|
|
|
|
{
|
|
|
|
$not = new Not($v);
|
|
|
|
$this->assertTrue($not->assert($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalidNot
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
2011-04-28 01:41:12 +02:00
|
|
|
*/
|
|
|
|
public function testNotNotHaha($v, $input)
|
|
|
|
{
|
|
|
|
$not = new Not($v);
|
|
|
|
$this->assertFalse($not->assert($input));
|
|
|
|
}
|
|
|
|
|
2016-01-29 22:50:27 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider providerForSetName
|
|
|
|
*/
|
|
|
|
public function testNotSetName($v)
|
|
|
|
{
|
|
|
|
$not = new Not($v);
|
|
|
|
$not->setName('Foo');
|
|
|
|
|
|
|
|
$this->assertEquals('Foo', $not->getName());
|
|
|
|
$this->assertEquals('Foo', $v->getName());
|
|
|
|
}
|
|
|
|
|
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],
|
2016-11-06 18:45:44 +01:00
|
|
|
[new AllOf(new OneOf(new NumericVal(), new IntVal())), 13.37],
|
|
|
|
[new OneOf(new NumericVal(), new IntVal()), 13.37],
|
|
|
|
[Validator::oneOf(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
|
|
|
}
|