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
|
|
|
|
* @covers Respect\Validation\Rules\Not
|
|
|
|
* @covers Respect\Validation\Exceptions\NotException
|
|
|
|
*/
|
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
|
|
|
|
* @expectedException Respect\Validation\Exceptions\ValidationException
|
|
|
|
*/
|
|
|
|
public function testNotNotHaha($v, $input)
|
|
|
|
{
|
|
|
|
$not = new Not($v);
|
|
|
|
$this->assertFalse($not->assert($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForValidNot()
|
|
|
|
{
|
|
|
|
return array(
|
2015-10-07 16:46:57 +02:00
|
|
|
array(new IntVal(), ''),
|
|
|
|
array(new IntVal(), 'aaa'),
|
2015-04-15 14:53:12 +02:00
|
|
|
array(new AllOf(new NoWhitespace(), new Digit()), 'as df'),
|
|
|
|
array(new AllOf(new NoWhitespace(), new Digit()), '12 34'),
|
|
|
|
array(new AllOf(new AllOf(new NoWhitespace(), new Digit())), '12 34'),
|
2015-10-07 16:46:57 +02:00
|
|
|
array(new AllOf(new NoneOf(new Numeric(), new IntVal())), 13.37),
|
|
|
|
array(new NoneOf(new Numeric(), new IntVal()), 13.37),
|
|
|
|
array(Validator::noneOf(Validator::numeric(), Validator::intVal()), 13.37),
|
2011-04-28 01:41:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForInvalidNot()
|
|
|
|
{
|
|
|
|
return array(
|
2015-10-07 16:46:57 +02:00
|
|
|
array(new IntVal(), 123),
|
|
|
|
array(new AllOf(new OneOf(new Numeric(), new IntVal())), 13.37),
|
|
|
|
array(new OneOf(new Numeric(), new IntVal()), 13.37),
|
|
|
|
array(Validator::oneOf(Validator::numeric(), Validator::intVal()), 13.37),
|
2011-04-28 01:41:12 +02:00
|
|
|
);
|
|
|
|
}
|
2012-05-17 20:51:49 +02:00
|
|
|
}
|