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

Add support for enum in symfony property accessor hydrator #1118

Merged
merged 1 commit into from
Oct 2, 2022

Conversation

akalineskou
Copy link
Contributor

We're using enums for some properties, and for the fixtures to work we had to do a workaround because it was trying to set a string.

The workaround was basically to convert the enum value to an enum (which we assume is correct, else it should fail)

    public function setDummyEnum(DummyEnum|string $dummyEnum): void
    {
        if (is_string($dummyEnum)) {
            // alice fixture
            $dummyEnum = DummyEnum::from($dummyEnum);
        }

        $this->dummyEnum = $dummyEnum;
    }

Today I thought enough was enough, we needed a better solution since they were becoming more and more.

I'm not sure if that's where the fix should go, but that's where the exception was happening, so it was a good starting place.

Tested in a big project with no issues.

Copy link
Member

@theofidry theofidry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM; just a few nitpicks but the core of the code is good IMO

@akalineskou akalineskou force-pushed the master branch 2 times, most recently from 3ea2e8a to 9bed799 Compare October 1, 2022 11:35
@akalineskou akalineskou requested a review from theofidry October 1, 2022 23:23
@theofidry theofidry merged commit b9cdb0a into nelmio:master Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants