Skip to content

Commit cbd0695

Browse files
committed
Merge pull request #256 from henriquemoody/not-shortcut
Fix wrong behavior when calling `not()` rule
2 parents 856d8fd + fb54341 commit cbd0695

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

library/Validator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ public static function buildRule($ruleSpec, $arguments = array())
146146
*/
147147
public function __call($method, $arguments)
148148
{
149-
if ('not' === $method) {
150-
return $arguments ? static::buildRule($method, $arguments) : new Rules\Not($this);
149+
if ('not' === $method && empty($arguments)) {
150+
return new static(new Rules\Not($this));
151151
}
152152

153153
return $this->addRule(static::buildRule($method, $arguments));

tests/library/Respect/Validation/ValidatorTest.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,24 @@ public function testKeysAsValidatorNames()
9090
\-"" must be a valid date', $e->getFullMessage());
9191
}
9292
}
93-
}
9493

94+
/**
95+
* Regression test #174.
96+
*/
97+
public function testShouldReturnANewValidatorInstanceWhenTheNotRuleIsCalledWithoutAnyArgument()
98+
{
99+
$validator = new Validator();
100+
101+
$this->assertInstanceOf('Respect\Validation\Validator', $validator->not());
102+
}
103+
104+
/**
105+
* Regression test #174.
106+
*/
107+
public function testShouldReturnValidatorInstanceWhenTheNotRuleIsCalledWithArguments()
108+
{
109+
$validator = new Validator();
110+
111+
$this->assertSame($validator, $validator->not($validator->notEmpty()));
112+
}
113+
}

0 commit comments

Comments
 (0)