Add cross-version compatibility with WP 5.9 and WP < 5.9#20
Merged
Conversation
As of WP 5.9, the PHPUnit Polyfills are also used by WordPress itself and WordPress will try to autoload the Autoloader for the Polyfills. This will work fine if WordPress is fully installed, but for a partial install, like provided via the WP-CLI `scaffold` command, this can be problematic. Similarly, if the PHPUnit Polyfills are available, but in a different location than expected by WP Core, again, this can be problematic. As the PHPUnit Polyfills is also a requirement of WP Test Utils, we can get prevent any issues with this by loading the autoloader ahead of running the WordPress test bootstrap file.
… supported WP versions
With the introduction of the PHPUnit Polyfills in WP 5.9 and the backport of the availability of the PHPUnit Polyfills + the snake case test wrappers to WP 5.2 - 5.8, integration tests for plugins/themes which test against WP 5.2 - 5.9 (and higher) can start using modern PHPUnit assertions and expectations, as well as switch over to using the `snake_case` fixture method names.
There is a caveat to this however:
* Plugins/themes which test against older WP versions (< 5.2) don't have access to either the polyfills or the snake_case fixture method wrappers.
* Same goes for tests being run against the current WP `latest`, which is the last 5.8.x release (5.8.1), which doesn't yet include the changes.
* Same goes for tests being run against all WP 5.2 - 5.8 minors which were released before today.
This commit:
* Introduces the snake_case fixture method wrappers to the WP integration test `TestCase`.
* Introduces a second `TestCase` for the WP integration tests.
The original `TestCase` is suitable for use for older WP versions which don't include the test changes from WP 5.9.
The new `TestCase` is suitable for use with WP 5.9 and WP versions which *do* include the test changes from WP 5.9.
The new `TestCase` does not include the Polyfills as those will be inherited from WordPress.
* Both these test cases have exactly the same name `Yoast\WPTestUtils\WPIntegration\TestCase` so concrete test classes can extend this class safely.
Because of this, this class will no longer be loaded via the Composer classmap though.
Instead, the custom Autoloader, which was already in place for the WP Integration tests, has been adjusted to handle loading the correct version of the class depending on whether or not the WP version against which the tests are being run contains the (backported) changes from WP 5.9 or not.
Includes minor tweak to the PHPCS config to allow for the duplicate class.
Fixes 14
cef7de8 to
18e7e97
Compare
Collaborator
Author
|
I've done a test run based on this PR with the WP Importer plugin and all looks good. Merging. |
This file contains hidden or 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
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.
Integration tests: update the bootstrap for compatibility with WP 5.9
As of WP 5.9, the PHPUnit Polyfills are also used by WordPress itself and WordPress will try to autoload the Autoloader for the Polyfills.
This will work fine if WordPress is fully installed, but for a partial install, like provided via the WP-CLI
scaffoldcommand, this can be problematic.Similarly, if the PHPUnit Polyfills are available, but in a different location than expected by WP Core, again, this can be problematic.
As the PHPUnit Polyfills is also a requirement of WP Test Utils, we can get prevent any issues with this by loading the autoloader ahead of running the WordPress test bootstrap file.
Integration tests TestCase: double the class for full compat with all supported WP versions
With the introduction of the PHPUnit Polyfills in WP 5.9 and the backport of the availability of the PHPUnit Polyfills + the snake case test wrappers to WP 5.2 - 5.8, integration tests for plugins/themes which test against WP 5.2 - 5.9 (and higher) can start using modern PHPUnit assertions and expectations, as well as switch over to using the
snake_casefixture method names.There is a caveat to this however:
latest, which is the last 5.8.x release (5.8.1), which doesn't yet include the changes.This commit:
TestCase.TestCasefor the WP integration tests.The original
TestCaseis suitable for use for older WP versions which don't include the test changes from WP 5.9.The new
TestCaseis suitable for use with WP 5.9 and WP versions which do include the test changes from WP 5.9.The new
TestCasedoes not include the Polyfills as those will be inherited from WordPress.Yoast\WPTestUtils\WPIntegration\TestCaseso concrete test classes can extend this class safely.Because of this, this class will no longer be loaded via the Composer classmap though.
Instead, the custom Autoloader, which was already in place for the WP Integration tests, has been adjusted to handle loading the correct version of the class depending on whether or not the WP version against which the tests are being run contains the (backported) changes from WP 5.9 or not.
Includes minor tweak to the PHPCS config to allow for the duplicate class.
Fixes #14