Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Enum constraint not behave as expected #188

Open
ker0x opened this issue May 9, 2022 · 2 comments
Open

[1.x] Enum constraint not behave as expected #188

ker0x opened this issue May 9, 2022 · 2 comments
Labels
Bug Unconfirmed to inspect / reproduce
Milestone

Comments

@ker0x
Copy link

ker0x commented May 9, 2022

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.

@ogizanagi ogizanagi added Bug Unconfirmed to inspect / reproduce labels May 9, 2022
@ogizanagi ogizanagi added this to the 1.x milestone May 9, 2022
@ogizanagi
Copy link
Member

ogizanagi commented May 9, 2022

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):

public function testValidMultiple(): void
{
$this->validator->validate([
Gender::get(Gender::MALE),
Gender::get(Gender::FEMALE),
], new Enum([
'class' => Gender::class,
'multiple' => true,
]));
$this->assertNoViolation();
}

@ker0x
Copy link
Author

ker0x commented May 9, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Unconfirmed to inspect / reproduce
Projects
None yet
Development

No branches or pull requests

2 participants