Update: The WordPress core integration testing library now supports PHPUnit 9 and no longer requires a special PHPUnit 7 library. Our version of PHPUnit 7 has been discontinued and is no longer available.
More information may be found here.
A few months ago a new major version of PHP was released which brought many code style and functionality enhancements. A very useful update toward making PHP strict typed and running more computational complex programs natively on PHP.
If you are running automated tests on WordPress it’s likely you are running some form of the WordPress core integration testing library which is locked down to PHPunit version 7. Over the past couple years WordPress core was aware of this upcoming limitation and our team was watching/working closely with WordPress core to support upgrading to PHPUnit 8 (preferable 9) before PHP 8 was released. The decision was made that instead of upgrading PHPUnit support it would be better to create a workaround for the WordPress develop library directly. This allows PHP 8 to be used when testing WordPress core but not external testing suites.
Which brings us to the challenge:
- We need to be able to run our project on PHP 8 as most reputable hosts already have it enabled.
- We need to be able to have automated tests running against WordPress integrations.
Solution
Instead of swimming against the current of the WordPress team, we decided the best solution for all was to fork the PHPunit 7 source code and refactor it to support PHP 8. We now have a working maintainable fork which we can keep up to date with PHP version updates until the time comes when we can get WordPress core to support modern versions of PHPUnit.
As we expect this to be a temporary solution we did not publish the package to Packagist but you may still use it via Composer like so:
We’ve also include all requirements to compile a PHAR from source which may be done by:
- Clone the Git repo.
- Run
composer install
. - Build via
bash ./ant/bin/ant phar
.
For convenience we’ll include an already built PHAR on each new release. Version 7.5.20.1 may be downloaded here.
Conclusion
We will continue to support the necessary work to get WordPress core running on PHPUnit 8. In the meantime we have a workable solution.