Merge pull request #288 from deveplon/add-allow-null-value-in-subset-method

Add some validation to prevent PHP Warning when value in subset is null
This commit is contained in:
Willem Wollebrants 2019-08-15 16:36:07 +02:00 committed by GitHub
commit 4cf18608ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -489,7 +489,7 @@ class Validator
if (!is_array($params[0])) {
$params[0] = array($params[0]);
}
if (is_scalar($value)) {
if (is_scalar($value) || is_null($value)) {
return $this->validateIn($field, $value, $params);
}

View File

@ -1720,6 +1720,15 @@ class ValidateTest extends BaseTestCase
$this->assertFalse($v->validate());
}
public function testSubsetAcceptNullValue()
{
// rule value equals null
$v = new Validator(array('test_field' => null));
$v->rule('required', 'test_field');
$v->rule('subset', 'test_field', array('black', 45));
$this->assertFalse($v->validate());
}
public function testContainsUniqueValid()
{
// numeric values