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'),
|
2013-01-22 21:49:20 +01:00
|
|
|
array(new AllOf(new NoWhitespace, new Digit), 'as df')
|
2011-04-28 01:41:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForInvalidNot()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(new Int, 123),
|
2013-01-22 21:49:20 +01:00
|
|
|
array(new AllOf(new NoWhitespace, new Digit), '12 34')
|
2011-04-28 01:41:12 +02:00
|
|
|
);
|
|
|
|
}
|
2012-05-17 20:51:49 +02:00
|
|
|
}
|
2013-01-22 20:25:34 +01:00
|
|
|
|