Skip to content

Commit a552724

Browse files
authored
Fix Doctrine lengthValidator deprecation on null float/decimal values (#136)
1 parent 931eef1 commit a552724

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/Doctrine/Validator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function validateRecord(Doctrine_Record $record)
8989
*/
9090
public static function validateLength($value, $type, $maximumLength)
9191
{
92-
if ($maximumLength === null ) {
92+
if ($maximumLength === null || $value === null) {
9393
return true;
9494
}
9595
if ($type == 'timestamp' || $type == 'integer' || $type == 'enum') {

tests/ValidatorTestCase.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,19 @@ public function testIsValidType()
123123
$this->assertTrue(Doctrine_Validator::isValidType($var, 'object'));
124124
}
125125

126-
public function testValidate2()
126+
public function testIsValidLength()
127+
{
128+
// Test length is less than maximum length
129+
$this->assertTrue(Doctrine_Validator::validateLength(1.2345, "decimal", 5));
130+
131+
// Test null value is less than maximum length
132+
$this->assertTrue(Doctrine_Validator::validateLength(null, "decimal", 4));
133+
134+
// Test length is greater than maximum length
135+
$this->assertFalse(Doctrine_Validator::validateLength(1.2345, "decimal", 4));
136+
}
137+
138+
public function testValidate2()
127139
{
128140
$test = new ValidatorTest();
129141
$test->mymixed = "message";

0 commit comments

Comments
 (0)