What
When making an optional field required if another field is set, the validation is not correctly executed in the following case:
public function testCheckOptionalGetsRequiredValidation()
{
$this->validator->optional('foo')->lengthBetween(1, 2)->required(function ($values) {
return array_key_exists('bar', $values);
});
$result = $this->validator->validate(['bar' => true, 'foo' => '']);
$this->assertTrue($result->isNotValid());
}
What is expected
Since the bar field exists in the array, the lengthBetween validation should be executed. It looks like the "allowEmpty" rule is not removed
Note
This only happens when you enter an empty string, if you change the value of foo to lol-lol, you will get a proper validation exception.