WordPress 6.1 brought up its biggest update in terms of compatibility by allowing it to be upgraded and run against PHP 8, alongside this update, they have also updated their official Test Suite, which is used for Unit Testing, to support the indicated PHP version plus PHPUnit 8.* and PHPUnit 9.* (more details can be read in this article).

These updates affect existing WordPress MVC projects because they are only compatible with the old version of the TestSuite and PHPUnit 7.*.

WordPress MVC changes

To update WordPress MVC and make it compatible with the mentioned WordPress changes, the first thing that we need to do is to update our composer dependencies, as WordPress MVC packages have been updated and tested to work with PHP 8.

We change our PHPUnit version from 7.5.* to 9.* and to update composer dependencies we run the following command:

composer update

After our dependencies are updated, we need to proceed to download the latest version of the Test Suite which can be accomplished by running the test setup wizard command (see documentation) again, with the difference that we will indicate a new path location for the Test Suite:

php ayuco setup tests

Once the new Test Suite is downloaded and mapped into our phpunit.json file, we need to download a new dependency required called PHPUnit Polyfills:

composer require yoast/phpunit-polyfills --dev --with-dependencies

Then, we need to make sure this dependency is being loaded on the tests bootstrap file, to do this we will add the following line in the file tests/bootstrap.php right after the file comments section:

 * PHPUnit bootstrap file.
 * @author 10 Quality <http://www.10quality.com>
 * @license MIT
 * @package WPMVC\Commands
 * @version 1.1.12
require_once __DIR__ . '/../vendor/autoload.php';

Finally, we need to add a new filter function to load external plugins during plugins_loaded hook, to do this, the end of our bootstrap file should look like this:

 * Manually load the plugin being tested.
function _manually_load_wpmvc_project() {
    // Load WordPress MVC project
    require dirname( dirname( __FILE__ ) ) . '/plugin.php';
tests_add_filter( 'muplugins_loaded', '_manually_load_wpmvc_project' );

 * Manually load 3rd party plugins that are dependencies.
function _manually_load_external_plugins() {
    // ----------------------------
    // Load plugin dependencies here, example below:
    // require_once WP_CONTENT_DIR . '/plugins/woocommerce/woocommerce.php';
    // ----------------------------
tests_add_filter( 'plugins_loaded', '_manually_load_external_plugins' );

// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';

Previously, external plugins were loaded before our WordPress MVC project, inside _manually_load_wpmvc_project(), but this creates conflicts with some external plugins, such as WooCommerce, which need to be loaded later in the cycle, this is the reason why we are now separating the two.

As optional, we may want to include .phpunit.result.cache inside our .gitignore file so we do not push to our repository testing cache results.

Other compatibility changes

The changes above are the only ones required to make sure WordPress MVC runs with the latest version of WordPress Test Suite, if your project runs into additional compatibility issues, then most likely is because of new changes you will need to fix that were brought by PHP 8, WordPress and/or 3rd party plugins.