diff --git a/src/Symfony/Component/Validator/Constraints/Count.php b/src/Symfony/Component/Validator/Constraints/Count.php index 8de10edfc8..b11f994f58 100644 --- a/src/Symfony/Component/Validator/Constraints/Count.php +++ b/src/Symfony/Component/Validator/Constraints/Count.php @@ -43,6 +43,9 @@ class Count extends Constraint 'min' => $options, 'max' => $options, ]; + } elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) { + $options['min'] = $options['max'] = $options['value']; + unset($options['value']); } parent::__construct($options); diff --git a/src/Symfony/Component/Validator/Constraints/Length.php b/src/Symfony/Component/Validator/Constraints/Length.php index 79aa473204..996a1e479f 100644 --- a/src/Symfony/Component/Validator/Constraints/Length.php +++ b/src/Symfony/Component/Validator/Constraints/Length.php @@ -47,6 +47,9 @@ class Length extends Constraint 'min' => $options, 'max' => $options, ]; + } elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) { + $options['min'] = $options['max'] = $options['value']; + unset($options['value']); } parent::__construct($options); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php index 8416136fd4..01e23cc3b9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php @@ -195,4 +195,13 @@ abstract class CountValidatorTest extends ConstraintValidatorTestCase $this->assertEquals(5, $constraint->min); $this->assertEquals(5, $constraint->max); } + + public function testConstraintAnnotationDefaultOption() + { + $constraint = new Count(['value' => 5, 'exactMessage' => 'message']); + + $this->assertEquals(5, $constraint->min); + $this->assertEquals(5, $constraint->max); + $this->assertEquals('message', $constraint->exactMessage); + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php index 955d8b5564..f1daee534a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php @@ -237,11 +237,20 @@ class LengthValidatorTest extends ConstraintValidatorTestCase } } - public function testConstraintGetDefaultOption() + public function testConstraintDefaultOption() { $constraint = new Length(5); $this->assertEquals(5, $constraint->min); $this->assertEquals(5, $constraint->max); } + + public function testConstraintAnnotationDefaultOption() + { + $constraint = new Length(['value' => 5, 'exactMessage' => 'message']); + + $this->assertEquals(5, $constraint->min); + $this->assertEquals(5, $constraint->max); + $this->assertEquals('message', $constraint->exactMessage); + } }