diff --git a/library/Validator.php b/library/Validator.php index a7c8746e7..3e8b39983 100644 --- a/library/Validator.php +++ b/library/Validator.php @@ -146,8 +146,8 @@ public static function buildRule($ruleSpec, $arguments = array()) */ 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)); diff --git a/tests/library/Respect/Validation/ValidatorTest.php b/tests/library/Respect/Validation/ValidatorTest.php index 5bf14897a..c2b8166f3 100644 --- a/tests/library/Respect/Validation/ValidatorTest.php +++ b/tests/library/Respect/Validation/ValidatorTest.php @@ -90,5 +90,24 @@ public function testKeysAsValidatorNames() \-"" 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())); + } +}