PhpEnums
PhpEnums copied to clipboard
[1.x] Enum constraint not behave as expected
Since this commit, parameters order and signature for the Choice constraint has changed. As a result, the Enum constraint does not behave as expected.
For example, setting the multiple parameter on the Enum constraint result to be the callback parameter being set in the Choice constraint.
Hi @ker0x . How do you instantiate the constraint? Could you provide a concrete example where this is problematic? ideally, could you even provide a reproducer or a failing test case?
Note there is a test case asserting the current behavior should work (but perhaps incomplete): https://github.com/Elao/PhpEnums/blob/7d08ee23f97699abcee8c136ea1c4f3a8f8c12a6/tests/Unit/Bridge/Symfony/Validator/Constraint/EnumValidatorTest.php#L48-L59
@ogizanagi thanks for your quick reply. Actually it's working when using an array to configure the constraint but not with named arguments
// This works
#[Enum(['class' => EducationalSupport::class, 'asValue' => true, 'multiple' => true])]
// Throw a ConstraintDefinitionException with the following message "The Choice constraint expects a valid callback."
#[Enum(class: EducationalSupport::class, asValue: true, multiple: true)]