Преглед на файлове

[Validator] added support for '0' as default constraint option value

avalanche123 преди 15 години
родител
ревизия
f2c4f20e70
променени са 2 файла, в които са добавени 12 реда и са изтрити 1 реда
  1. 1 1
      src/Symfony/Components/Validator/Constraint.php
  2. 11 0
      tests/Symfony/Tests/Components/Validator/ConstraintTest.php

+ 1 - 1
src/Symfony/Components/Validator/Constraint.php

@@ -67,7 +67,7 @@ class Constraint
                     $invalidOptions[] = $option;
                 }
             }
-        } else if ($options) {
+        } else if ($options !== null && ! (is_array($options) && count($options) === 0)) {
             $option = $this->defaultOption();
 
             if (is_null($option)) {

+ 11 - 0
tests/Symfony/Tests/Components/Validator/ConstraintTest.php

@@ -82,4 +82,15 @@ class ConstraintTest extends \PHPUnit_Framework_TestCase
         $constraint->addImplicitGroupName('Foo');
         $this->assertEquals(array('Default', 'Foo'), $constraint->groups);
     }
+
+    public function testAllowsSettingZeroRequiredPropertyValue()
+    {
+        $constraint = new ConstraintA(0);
+        $this->assertEquals(0, $constraint->property2);
+    }
+
+    public function testCanCreateConstraintWithNoDefaultOptionAndEmptyArray()
+    {
+        new ConstraintB(array());
+    }
 }