diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index b92def2..94af820 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -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); } diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index fc9f229..28cacfc 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -484,7 +484,7 @@ class ValidateTest extends BaseTestCase $v->rule('lengthMin', 'str', 4); $this->assertTrue($v->validate()); } - + public function testLengthMinValidAltSyntax() { $v = new Valitron\Validator(array('username' => 'martha')); @@ -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