-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport support for the
AssertObjectProperty
polyfill
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.
- Loading branch information
Showing
6 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Yoast\WPTestUtils\WPIntegration; | ||
|
||
use WP_UnitTestCase; | ||
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectProperty; | ||
use Yoast\WPTestUtils\Helpers\ExpectOutputHelper; | ||
|
||
/** | ||
* Basic test case for use with a WP Integration test test suite. | ||
* | ||
* This test case extends the WordPress native base test case and | ||
* adds a limited set of test helper functions. | ||
* | ||
* The WordPress native base test case will include all relevant | ||
* polyfills to allow for using PHPUnit 9.x assertion and expectation syntax | ||
* with the exception of the PHPUnit 9.6.11+/PHPUnit Polyfills 1.1.0+ | ||
* assertObject*() polyfills, as that polyfill was added after the backport. | ||
* | ||
* This test case makes sure the assertObject*() polyfills are still | ||
* available when running tests against WP versions below 5.9, which do | ||
* include the backported changes from WP 5.9, but don't include the | ||
* polyfill which was released after the backports were done. | ||
* | ||
* This test case is suitable for use with: | ||
* - WP 5.2.13 and higher; | ||
* - WP 5.3.10 and higher; | ||
* - WP 5.4.8 and higher; | ||
* - WP 5.5.7 and higher; | ||
* - WP 5.6.6 and higher; | ||
* - WP 5.7.4 and higher; | ||
* - WP 5.8.1 and higher; | ||
* | ||
* The included autoloader will automatically load the correct test case for | ||
* the WordPress version the tests are being run on. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
abstract class TestCase extends WP_UnitTestCase { | ||
|
||
use AssertObjectProperty; | ||
use ExpectOutputHelper; | ||
|
||
} |