Validation
Validation copied to clipboard
keyValue exception message may be redundant
In the case where we're missing one of the keys the KeyValue message is redundant. For example the following code...
try {
$test = ['password' => '12345'];
v::key('password', v::stringType()->notEmpty())
->key('password_confirmation', v::stringType()->notEmpty())
->keyValue('password_confirmation', 'equals', 'password')
->assert($test);
} catch (NestedValidationException $e) {
var_dump($e->getMessages());
}
results in the following dump:
array(2) {
["password_confirmation"]=>
string(41) "Key password_confirmation must be present"
["keyValue"]=>
string(43) "Key "password_confirmation" must be present"
}
Seems like the keyValue message should be suppressed if one of it's key dependencies is missing.
I agree it should be suppressed. It is hard to do though!
Have you tried playing with the KeySet rule? https://github.com/Respect/Validation/blob/1.1/docs/rules/KeySet.md
Since it wraps multiple keys, it might report the exception in a friendlier manner.
This seems to have been fixed already in 2.2, as I'm getting messages like this:
(
[password] => password must be of type string
[password_confirmation] => password_confirmation must equal "password"
)
Feel free to reopen if you're still experiencing this.