Yoast / yoast-acf-analysis

WordPress plugin that adds the content of all ACF fields to the Yoast SEO score analysis.
https://wordpress.org/plugins/acf-content-analysis-for-yoast-seo/
GNU General Public License v3.0
61 stars 20 forks source link

Tests: make the testsuite compatible with PHPUnit 9 and test against PHP 8 #281

Closed jrfnl closed 3 years ago

jrfnl commented 3 years ago

Summary

This PR can be summarized in the following changelog entry:

Relevant technical choices:

Replaces earlier PR #278

Composer: require Yoast/wp-test-utils

The install is done based on PHP 5.6 and includes updating the dependencies from PHPUnit itself within the constraints of maintaining compatibility with PHP 5.6.

This new package adds the following features:

Refs:

Tests: selectively switch over to the Yoast\WPTestUtils\BrainMonkey\TestCase

Not all test classes in the ACF testsuite are based on BrainMonkey and those that are generally just set up the BrainMonkey native stubs and don't add the other stubs commonly used by Yoast plugins.

With that in mind:

Tests: selectively switch over to the Yoast\PHPUnitPolyfills\TestCases\TestCase

For those test classes in the ACF testsuite which are not based on BrainMonkey, we don't need the overhead of loading the BrainMonkey framework, but do want the PHPUnit cross-version compatibility.

So, the use statements referring to the PHPUnit native PHPUnit\Framework\TestCase have been replaced with use statements for the PHPUnit cross-version compatible Yoast\PHPUnitPolyfills\TestCases\TestCase.

Tests: modernize used assertions

The PHPUnit Polyfills allows for using PHPUnit 9.x assertions, even when the tests are being run on older PHPUnit versions.

This updates select assertions to the modern PHPUnit syntax, most notably, it switches out the following assertions:

Travis: run the tests against PHP 8/nightly

Now the tests are fully compatible with PHPUnit 9, the test suite can be run on PHP 8.

To that end, we run a composer update for just and only the test dependencies on PHP 8 to make sure that the test dependencies available are compatible with PHP 8. And as the composer.json contains a hard-coded platform.php setting, we use ignore-platform-reqs to get round that setting.

Includes:

PHPUnit config: minor tweaks

Based on this configuration, the strict code coverage for this testsuite is currently 51.76%.

Test instructions

This PR can be tested by following these steps:

To test locally, it will be simplest to:

  1. Run composer install.
  2. Run composer test on any PHP version below 8.0 and see the tests pass, including a more accurate assertion count (72 compared to 52 previously, due to Mockery expectations now being counted). This confirms that the changes to the TestCase and the assertion update to use PHPUnit 9.x syntax works correctly cross-version as the PHPUnit version installed based on the composer.lock file will be PHPUnit 5.7.27.
  3. Switch to PHP 8.
  4. Run composer update yoast/wp-test-utils --with-dependencies --ignore-platform-reqs
  5. Run composer test to see the tests running and passing on PHP 8 in combination with PHPUnit 9.x. This confirms that the tests can now run cross-version on all PHPUnit versions between PHPUnit 5.7 and PHPUnit 9.x and that the tests run and pass on PHP 8.

Note: this doesn't confirm full PHP 8 compatibility yet as the test code coverage as noted above is only ~50%.

jrfnl commented 3 years ago

Code coverage overview: image