respect-validation/tests/Rules/NotTest.php

66 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace Respect\Validation\Rules;
2012-05-17 21:16:45 +02:00
use Respect\Validation\Validator;
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
}
/**
* @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
}
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),
);
}
public function providerForInvalidNot()
{
return array(
array(new Int, ''),
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),
);
}
2012-05-17 20:51:49 +02:00
}
2013-01-22 20:25:34 +01:00