2011-04-28 01:41:12 +02:00
|
|
|
<?php
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2012-05-17 21:16:45 +02:00
|
|
|
use Respect\Validation\Validator;
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2012-05-17 21:16:45 +02:00
|
|
|
public function testShortcutNot()
|
2012-05-06 02:06:13 +02:00
|
|
|
{
|
2012-05-17 21:16:45 +02:00
|
|
|
$this->assertTrue(Validator::int()->not()->assert('afg'));
|
2012-05-06 02:06:13 +02:00
|
|
|
}
|
|
|
|
|
2011-04-28 01:41:12 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalidNot
|
|
|
|
* @expectedException Respect\Validation\Exceptions\ValidationException
|
|
|
|
*/
|
|
|
|
public function testNotNotHaha($v, $input)
|
|
|
|
{
|
|
|
|
$not = new Not($v);
|
|
|
|
$this->assertFalse($not->assert($input));
|
|
|
|
}
|
|
|
|
|
2012-05-06 02:06:13 +02:00
|
|
|
/**
|
|
|
|
* @expectedException Respect\Validation\Exceptions\ValidationException
|
|
|
|
*/
|
2012-05-17 21:16:45 +02:00
|
|
|
public function testShortcutNotNotHaha()
|
2012-05-06 02:06:13 +02:00
|
|
|
{
|
2012-05-17 21:16:45 +02:00
|
|
|
$this->assertFalse(Validator::int()->not()->assert(10));
|
2012-05-06 02:06:13 +02:00
|
|
|
}
|
|
|
|
|
2011-04-28 01:41:12 +02:00
|
|
|
public function providerForValidNot()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(new Int, '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'),
|
|
|
|
array(new AllOf(new NoneOf(new Numeric(), new Int())), 13.37),
|
|
|
|
array(new NoneOf(new Numeric(), new Int()), 13.37),
|
|
|
|
array(Validator::noneOf(Validator::numeric(), Validator::int()), 13.37),
|
2011-04-28 01:41:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForInvalidNot()
|
|
|
|
{
|
|
|
|
return array(
|
2013-01-23 08:49:20 +01:00
|
|
|
array(new Int, ''),
|
2011-04-28 01:41:12 +02:00
|
|
|
array(new Int, 123),
|
2015-04-15 14:53:12 +02:00
|
|
|
array(new AllOf(new OneOf(new Numeric(), new Int())), 13.37),
|
|
|
|
array(new OneOf(new Numeric(), new Int()), 13.37),
|
|
|
|
array(Validator::oneOf(Validator::numeric(), Validator::int()), 13.37),
|
2011-04-28 01:41:12 +02:00
|
|
|
);
|
|
|
|
}
|
2012-05-17 20:51:49 +02:00
|
|
|
}
|
2013-01-22 20:25:34 +01:00
|
|
|
|