respect-validation/tests/library/Respect/Validation/Rules/NotTest.php

60 lines
1.3 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'),
array(new AllOf(new NoWhitespace, new Digits), 'as df')
);
}
public function providerForInvalidNot()
{
return array(
array(new Int, 123),
array(new AllOf(new NoWhitespace, new Digits), '12 34')
);
}
2012-05-17 20:51:49 +02:00
}