PhpEnums icon indicating copy to clipboard operation
PhpEnums copied to clipboard

[1.x] Enum constraint not behave as expected

Open ker0x opened this issue 3 years ago • 2 comments
trafficstars

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.

ker0x avatar May 09 '22 13:05 ker0x

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 avatar May 09 '22 14:05 ogizanagi

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

ker0x avatar May 09 '22 14:05 ker0x