Define names for the child of Not rule

This commit is contained in:
Caio César Tavares 2016-01-29 19:50:27 -02:00 committed by Henrique Moody
parent 6d04b77762
commit d1c3b2596e
2 changed files with 30 additions and 0 deletions

View file

@ -23,6 +23,13 @@ class Not extends AbstractRule
$this->rule = $rule;
}
public function setName($name)
{
$this->rule->setName($name);
return parent::setName($name);
}
public function validate($input)
{
return (false == $this->rule->validate($input));

View file

@ -39,6 +39,18 @@ class NotTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($not->assert($input));
}
/**
* @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()
{
return [
@ -62,4 +74,15 @@ class NotTest extends \PHPUnit_Framework_TestCase
[Validator::oneOf(Validator::numeric(), Validator::intVal()), 13.37],
];
}
public function providerForSetName()
{
return [
[new IntVal()],
[new AllOf(new Numeric, new IntVal)],
[new Not(new Not(new IntVal()))],
[Validator::intVal()->setName('Bar')],
[Validator::noneOf(Validator::numeric(), Validator::intVal())],
];
}
}