Fix wrong behavior when calling not() rule

This commit is contained in:
Henrique Moody 2015-01-19 20:12:07 -02:00
parent 856d8fd1d1
commit fb54341fb2
2 changed files with 22 additions and 3 deletions

View file

@ -146,8 +146,8 @@ class Validator extends AllOf
*/
public function __call($method, $arguments)
{
if ('not' === $method) {
return $arguments ? static::buildRule($method, $arguments) : new Rules\Not($this);
if ('not' === $method && empty($arguments)) {
return new static(new Rules\Not($this));
}
return $this->addRule(static::buildRule($method, $arguments));

View file

@ -90,5 +90,24 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
\-"" must be a valid date', $e->getFullMessage());
}
}
}
/**
* Regression test #174.
*/
public function testShouldReturnANewValidatorInstanceWhenTheNotRuleIsCalledWithoutAnyArgument()
{
$validator = new Validator();
$this->assertInstanceOf('Respect\Validation\Validator', $validator->not());
}
/**
* Regression test #174.
*/
public function testShouldReturnValidatorInstanceWhenTheNotRuleIsCalledWithArguments()
{
$validator = new Validator();
$this->assertSame($validator, $validator->not($validator->notEmpty()));
}
}