Skip to content
New issue

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

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

Already on GitHub? # to your account

Add support for enums in error message #292

Merged

Conversation

gordinskiy
Copy link
Contributor

Attempt to resolve #289

@ReSpawN
Copy link

ReSpawN commented Oct 11, 2024

God yes. I just bumped into this with Assert::nullOrOneOf($type, self::$allowedCarbonTypes)

Big +1

@shadowhand
Copy link
Collaborator

@gordinskiy recognizing that it has been a year... 😅 would you please rebase this?

@gordinskiy gordinskiy force-pushed the feature/enums-in-error-message branch 2 times, most recently from 4dd4336 to 6a7c456 Compare October 18, 2024 20:16
@gordinskiy
Copy link
Contributor Author

@shadowhand done

@shadowhand
Copy link
Collaborator

@gordinskiy will you please add a test for this? It will need to be restricted to PHP versions that support Enum, of course.

@gordinskiy gordinskiy force-pushed the feature/enums-in-error-message branch from 6a7c456 to 1ad20d0 Compare October 19, 2024 19:26
@gordinskiy
Copy link
Contributor Author

Added test case for error message with enum in it.

tests/AssertTest.php Outdated Show resolved Hide resolved
@gordinskiy gordinskiy force-pushed the feature/enums-in-error-message branch from 1ad20d0 to 8144e25 Compare October 19, 2024 21:50
@gordinskiy
Copy link
Contributor Author

gordinskiy commented Oct 21, 2024

Ok, tests fails on old versions.
We can wrap enum declaration inside eval.
Would this be an acceptable solution or maybe you have a better one?

if (PHP_VERSION_ID >= ENUM_INTRODUCTION_VERSION_ID) {
    eval("
        enum TestEnum
        {
            case CaseName;
        }
    ");
}

@shadowhand
Copy link
Collaborator

shadowhand commented Oct 23, 2024

Rather than doing an eval, can it be placed into a separate file and included conditionally? I don't want to use eval, even in a test, if it can be helped.

@gordinskiy gordinskiy force-pushed the feature/enums-in-error-message branch from 316de36 to 137f51b Compare October 23, 2024 13:40
@gordinskiy
Copy link
Contributor Author

Updated test

@shadowhand shadowhand merged commit f23349f into webmozarts:master Oct 23, 2024
11 checks passed
@shadowhand
Copy link
Collaborator

Thank you!

@gordinskiy gordinskiy deleted the feature/enums-in-error-message branch October 23, 2024 23:42
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for enums in error message
4 participants