Skip to content

Commit

Permalink
Fix wrong behavior when calling not() rule
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Jan 19, 2015
1 parent 856d8fd commit fb54341
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions library/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
21 changes: 20 additions & 1 deletion tests/library/Respect/Validation/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

0 comments on commit fb54341

Please sign in to comment.