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

This commit is contained in:
avalanche123 2010-07-04 12:08:06 -04:00 committed by Bernhard Schussek
parent 8c9f9de086
commit f2c4f20e70
2 changed files with 12 additions and 1 deletions

View File

@ -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)) {

View File

@ -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());
}
}