Skip to content
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

Release version 1.0.0 #25

Merged
merged 28 commits into from
Sep 27, 2021
Merged

Release version 1.0.0 #25

merged 28 commits into from
Sep 27, 2021

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Sep 27, 2021

No description provided.

jrfnl and others added 28 commits June 22, 2021 03:54
Turns out the default setting for `error_reporting` used by the SetupPHP action is `error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT` and `display_errors` is set to `Off`.

For the purposes of CI, I'd recommend running with `E_ALL` and `display_errors=On` to ensure **all** PHP notices are shown.
…orting

GH Actions: set error reporting to E_ALL
Setting the minimum version to `1.0.1` ensures install will comply with the minimum version expected for WordPress 5.9.
Composer: upgrade the PHPUnit Polyfills
Update the Parallel Lint `dev` dependency to use v `1.3.1` as a minimum. The new release has improved PHP 8.1 support.

Ref: https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/tag/v1.3.1
... which includes PHP Parallel Lint by design, so no need to require it separately anymore.

Ref: https://github.com/Yoast/yoastcs/releases
* Ensure all code in the global namespace is prefixed - with the exception of the WP constants declarations in the BrainMonket test bootstrap.
* Ignore camelCase object name depth rules for the tests.
* For fixtures containing test methods, no `@covers` tags are needed. Those are not the real tests.
…setup

As the WP-CLI `scaffold` command is an often-used basis for setting up the integration tests, this commit adds a native check to WP Test Utils in the integration tests `get_path_to_wp_test_dir()` function for the WP native test bootstrap in the typical location used by the WP-CLI `scaffold` `install-wp-tests.sh` script.

This means that if the `install-wp-tests.sh` script is used without adjustments, the path to the WP native test bootstrap should be findable by WP Test Utils without needing to set the `WP_TESTS_DIR` constant.

Fixes 12
…fold-script

Integration test bootstrap: add fall-back support for typical WP-CLI setup
Follow up to 11

As per the changelog of the PHPUnit Polyfills, version 1.0.0 introduced three new polyfill traits.

Those traits were not yet included in the `Yoast\WPTestUtils\WPIntegration\TestCase`. Fixed now.

Ref: https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/1.0.0
…-for-polyfills-1.0.0

TestCase: update for PHPUnit Polyfills 1.0.0
* Add information to the docblock for the `get_path_to_wp_test_dir()` function about the new WP-CLI scaffold command fall-back functionality as introduced in 16.
* Fix an incorrect function reference elsewhere.
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
Add cross-version compatibility with WP 5.9 and WP < 5.9
PHPUnit just released version 9.5.10 and 8.5.21.

This contains a particular (IMO breaking) change:

> * PHPUnit no longer converts PHP deprecations to exceptions by default (configure `convertDeprecationsToExceptions="true"` to enable this)

Let's unpack this:

Previously (PHPUnit < 9.5.10/8.5.21), if PHPUnit would encounter a PHP native deprecation notice, it would:
1. Show a test which causes a deprecation notice to be thrown as **"errored"**,
2. Show the **first** deprecation notice it encountered and
3. PHPUnit would exit with a **non-0 exit code** (2), which will fail a CI build.

As of PHPUnit 9.5.10/8.5.21, if PHPUnit encounters a PHP native deprecation notice, it will no longer do so. Instead PHPUnit will:
1. Show a test which causes a PHP deprecation notice to be thrown as **"risky"**,
2. Show the **all** deprecation notices it encountered and
3. PHPUnit will exit with a **0 exit code**, which will show a CI build as passing.

This commit reverts PHPUnit to the previous behaviour by adding `convertDeprecationsToExceptions="true"` to the PHPUnit configuration.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/9.5/ChangeLog-8.5.md
* https://github.com/sebastianbergmann/phpunit/blob/9.5/ChangeLog-9.5.md
The stubbed `is_multisite()` function would previously always return `false`.

For integration tests, the WP Core test suite supports setting a `WP_TESTS_MULTISITE` PHP constant in the `phpunit.xml[.dist]` configuration to indicate that the test suite should be run in a multisite context.

While BrainMonkey tests are run stand-alone, this commit changes the behaviour of the `is_multisite()` stub to respect a potentially set `WP_TESTS_MULTISITE` constant, allowing for BrainMonkey based tests to test specific logic paths in plugin/theme code which are only run in a multisite context.
…e-is-multisite-stub

BrainMonkey\YoastTestCase: make the `is_multisite()` stub more versatile
* Improve readability.
* Update for changes includes in v 1.0.0.
* Add more detailed information about why this library is useful and what it solves, including information about the test changes in WP 5.9.
* Add second implementation example for integration test bootstraps.
* Minor other tweaks.
…ests

README: update for version 1.0.0 and WP 5.9
@jrfnl jrfnl added this to the 1.0.0 milestone Sep 27, 2021
@jrfnl jrfnl merged commit 21df3a0 into main Sep 27, 2021
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.

None yet

1 participant