-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[PhpUnitBridge] Add enum_exists mock
#48516
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
Conversation
3fa53f7 to
664ab09
Compare
670b219 to
f53feae
Compare
41aa4ca to
bb1bc08
Compare
enum_exists mockenum_exists mock
enum_exists mockenum_exists mock
|
Question: Can I use this mocking mechanism to test code that looks like this? if (class_exists(SomeClass::class) && !enum_exists(SomeClass::class)) {
// do something
}This is a common pattern if you want to check to make sure a class is actually a class because an enum would also pass a |
bb1bc08 to
838b5b8
Compare
|
@derrabus It doesn't seem. Actually, if you declare a mocked class, it will return |
|
Maybe we should make a difference, yes. 🤔 What do you think? Since you're contributing this feature, you must have some use case for it? |
838b5b8 to
87ce345
Compare
|
I actually don't have the use case. This contribution idea came to me when crawling the bridge documentation 😄 I updated the code so there's a diff between classes and enums. I added |
| public static function withMockedEnums(array $enums) | ||
| { | ||
| self::$enums = $enums; | ||
| self::$classes += $enums; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
87ce345 to
bd95687
Compare
bd95687 to
8d3e897
Compare
| "symfony/deprecation-contracts": "^2.5|^3.0", | ||
| "symfony/error-handler": "^5.4|^6.0" | ||
| "symfony/error-handler": "^5.4|^6.0", | ||
| "symfony/polyfill-php81": "^1.27" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this: #48516 (comment) 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, okay, it's just a dev dependency, so I guess it's fine.
|
Thank you @alexandre-daubois. |
…daubois) This PR was merged into the 6.3 branch. Discussion ---------- [PhpUnitBridge] Fix `enum_exists` mock tests | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | _NA_ | License | MIT | Doc PR | _NA_ This fixes some tests broken by #48516. It seems that PHP needs the file to be required to be fully aware of the enum. Otherwise, even `\class_exists` and `\enum_exists` are returning false on `ExistingEnumReal::class`. Commits ------- 693ade3 [PhpUnitBridge] Fix `enum_exists` mock tests
…ois) This PR was merged into the 6.3 branch. Discussion ---------- [PHPUnitBridge] Add `enum_exists` mock Related to symfony/symfony#48516 Commits ------- d18c238 [PhpUnitBridge] Add `enum_exists` mock
Uh oh!
There was an error while loading. Please reload this page.