[Validator] Fix annotation default for @Count and @Length
This commit is contained in:
parent
c79e52aa7b
commit
7bfb8c1a4c
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue