Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enum error message consistency #9350

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

Merged
merged 18 commits into from
Aug 23, 2022
Merged

Enum error message consistency #9350

merged 18 commits into from
Aug 23, 2022

Conversation

ollieread
Copy link
Contributor

@ollieread ollieread commented Aug 16, 2022

This PR addresses the points raised in #9262 by doing the following:

Updating magic method exception messages

Previously the error message:

Enum may not include magic method %s

Was only used for:

  • __sleep
  • __wakeup
  • __set_state

All of which I believe are "technically" not magic methods, whereas all of the other true magic methods gave the error message:

Enum may not include %s

This PR updates it so that all true magic methods also give the following error:

Enum may not include magic method %s

Normalising double quote usage in error messages

Enum error messages were inconsistent in their usage of double quotes with an enum name, as well as with values.

This PR changes the following error messages:

Properties

Enum "%s" may not include properties

Is now

Enum %s may not include properties

Backing

"%s" is not a valid backing value for enum "%s"

Is now

"%s" is not a valid backing value for enum %s

In the spirit of keeping this consistent, double quotes have been added to the value when the backing type is int.

Added missing tests

I've also added tests for all of the magic methods that weren't previously covered.

Stringable

Nothing was done with the Stringable interface, as originally planned, because the usage of __toString was always caught before the interface.

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

The rest looks like a clear improvement. 👍

@iluuu1994
Copy link
Member

@ollieread Btw you can add --bless to the test parameters to automatically fix the test expectations. You might also want to ./configure with --enable-zend-test to run the internal enum tests.

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

The rest looks good, and I appreciate the effort to keep these messages consistent :)

@@ -0,0 +1,15 @@
--TEST--
Enum __clone
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
Enum __clone
Enums cannot include the __clone magic method

Copy link
Member

Choose a reason for hiding this comment

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

The rest of the tests could profit from this change

@ollieread
Copy link
Contributor Author

The rest looks good, and I appreciate the effort to keep these messages consistent :)

Thanks, and I'm happy to help. As an aside, if you know any other bits that could do with some improvement to consistency, I'm happy to look at them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants