-
Notifications
You must be signed in to change notification settings - Fork 3
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
Backport support for the AssertObjectProperty
polyfill
#64
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jrfnl
force-pushed
the
JRF/update-for-phpunit-polyfills-1.1.0
branch
2 times, most recently
from
September 23, 2023 06:08
d74a1e1
to
1bc09eb
Compare
PHPUnit 10.1.0 introduced two new assertions - `assertObjectHasProperty()` and `assertObjectNotHasProperty()` - to replace the `assertObjectHasAttribute() and `assertObjectNotHasAttribute()` methods, which were deprecated in PHPUnit 9.6.0 and removed in PHPUnit 10.0.0. These two new assertions have since been backported to PHPUnit 9.x in PHPUnit 9.6.11 to allow for getting rid of the deprecation notice and making preparing for PHPUnit 10 more smooth. The PHPUnit Polyfills have followed suit and the 1.1.0 release contains polyfills for the backported `assertObjectHasProperty()` and `assertObjectNotHasProperty()` methods. For the WP Test Utils package, this caused an interesting conundrum: * WP 6.4 - which enforces the use of PHPUnit Polyfills 1.1.0+ - will have the new polyfills available. * WP 5.9 - 6.3 will have the new polyfills available _if the test dependencies are updated and PHPUnit Polyfills 1.1.0+ is used_. * WP 5.2 - 5.9 versions, which include the backports, will **not** have the new polyfills available. * WP 5.2 - 5.9 versions, which **don't** include the backports, will **not** have the new polyfills available. * WP < 5.2 will **not** have the new polyfills available. Previously the WP Test Utils would have two test cases available for integration tests: * One for use with WP 5.9+ and with WP versions < 5.9 which included the backports. * One for use with WP < 5.2 and with WP versions < 5.9 which do not include the backports. To solve the conundrum, this commit: * Updates the minimum version of the PHPUnit Polyfills to 1.1.0. * Add the new polyfill to the test case which is used for WP < 5..2 and for WP versions < 5.9 which do not include the backports. * Introduces a third test case for integration tests against WP 5.2 - 5.8 versions, which _do_ include the backports, but not the new polyfill. While this third polyfill might technically not be needed, I've seen too many issues with traits colliding on older PHP versions to be willing to take that risk. * Updates the autoloader to load the correct test case. This should ensure that the new polyfill is available in all cases.
jrfnl
force-pushed
the
JRF/update-for-phpunit-polyfills-1.1.0
branch
from
September 24, 2023 06:35
1bc09eb
to
b0a3817
Compare
GaryJones
approved these changes
Sep 25, 2023
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.
On local PHP 8.2, I:
- updated
composer.json
to bedev-JRF/update-for-phpunit-polyfills-1.1.0
- ran
composer update
- locally ran tests on a plugin - all OK.
- updated
$this->assertTrue( property_exists( $coauthor, 'ID' ) );
to be$this->assertObjectHasProperty( 'ID', $coauthor );
- locally ran tests again - still all OK
(No surprises for PHP 8.2 and latest code.)
I then pushed the changes to GitHub which ran a workflow and ran tests on a selection of older WP/PHP including on WP 5.7 + PHP 7.1. They all passed.
Thank you @GaryJones for testing and confirming this works! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHPUnit 10.1.0 introduced two new assertions -
assertObjectHasProperty()
andassertObjectNotHasProperty()
- to replace theassertObjectHasAttribute()
andassertObjectNotHasAttribute()
methods, which were deprecated in PHPUnit 9.6.0 and removed in PHPUnit 10.0.0.These two new assertions have since been backported to PHPUnit 9.x in PHPUnit 9.6.11 to allow for getting rid of the deprecation notice and making preparing for PHPUnit 10 more smooth.
The PHPUnit Polyfills have followed suit and the 1.1.0 release contains polyfills for the backported
assertObjectHasProperty()
andassertObjectNotHasProperty()
methods.For the WP Test Utils package, this caused an interesting conundrum:
Previously the WP Test Utils would have two test cases available for integration tests:
To solve the conundrum, this commit:
This should ensure that the new polyfill is available in all cases.