respect-validation/tests/unit/Rules/NotTest.php

89 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2015-06-08 16:47:14 +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.
*/
namespace Respect\Validation\Rules;
2012-05-17 21:16:45 +02:00
use Respect\Validation\Validator;
/**
* @group rule
2017-02-04 14:01:14 +01:00
* @covers \Respect\Validation\Rules\Not
* @covers \Respect\Validation\Exceptions\NotException
*/
class NotTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerForValidNot
*/
public function testNot($v, $input)
{
$not = new Not($v);
$this->assertTrue($not->assert($input));
}
/**
* @dataProvider providerForInvalidNot
2017-02-04 14:01:14 +01:00
* @expectedException \Respect\Validation\Exceptions\ValidationException
*/
public function testNotNotHaha($v, $input)
{
$not = new Not($v);
$this->assertFalse($not->assert($input));
}
2016-01-29 22:50:27 +01:00
/**
* @dataProvider providerForSetName
*/
public function testNotSetName($v)
{
$not = new Not($v);
$not->setName('Foo');
$this->assertEquals('Foo', $not->getName());
$this->assertEquals('Foo', $v->getName());
}
public function providerForValidNot()
{
2015-10-18 03:44:47 +02:00
return [
[new IntVal(), ''],
[new IntVal(), 'aaa'],
[new AllOf(new NoWhitespace(), new Digit()), 'as df'],
[new AllOf(new NoWhitespace(), new Digit()), '12 34'],
[new AllOf(new AllOf(new NoWhitespace(), new Digit())), '12 34'],
2016-11-06 18:45:44 +01:00
[new AllOf(new NoneOf(new NumericVal(), new IntVal())), 13.37],
[new NoneOf(new NumericVal(), new IntVal()), 13.37],
[Validator::noneOf(Validator::numericVal(), Validator::intVal()), 13.37],
2015-10-18 03:44:47 +02:00
];
}
public function providerForInvalidNot()
{
2015-10-18 03:44:47 +02:00
return [
[new IntVal(), 123],
2016-11-06 18:45:44 +01:00
[new AllOf(new OneOf(new NumericVal(), new IntVal())), 13.37],
[new OneOf(new NumericVal(), new IntVal()), 13.37],
[Validator::oneOf(Validator::numericVal(), Validator::intVal()), 13.37],
2015-10-18 03:44:47 +02:00
];
}
2016-01-29 22:50:27 +01:00
public function providerForSetName()
{
return [
[new IntVal()],
2016-11-06 18:45:44 +01:00
[new AllOf(new NumericVal(), new IntVal())],
2016-01-29 22:50:27 +01:00
[new Not(new Not(new IntVal()))],
[Validator::intVal()->setName('Bar')],
2016-11-06 18:45:44 +01:00
[Validator::noneOf(Validator::numericVal(), Validator::intVal())],
2016-01-29 22:50:27 +01:00
];
}
2012-05-17 20:51:49 +02:00
}