Troubleshooting: Required version of DTRT WP Plugin can not be loaded - dotherightthing/wpdtrt-plugin-boilerplate GitHub Wiki

Status

  • Stable @ 1.4.26
  • Revisit [TODO CHECK]

Trigger

  1. yarn run version
  2. Commit
  3. Push to Github
  4. Travis runs

Error message

If you have debugging enabled, a message similar to this will be output to debug.log:

[01:28:09] ========== phpunit ========== [01:28:09]
Installing... Running as single site... To run multisite, use -c tests/phpunit/multisite.xml PHP Fatal error: Class 'DoTheRightThing\WPPlugin\r_1_4_14\Plugin' not found in /home/travis/build/dotherightthing/wpdtrt-gallery/vendor/dotherightthing/wpdtrt-contentsections/src/class-wpdtrt-contentsections-plugin.php on line 19 Fatal error: Class 'DoTheRightThing\WPPlugin\r_1_4_14\Plugin' not found in /home/travis/build/dotherightthing/wpdtrt-gallery/vendor/dotherightthing/wpdtrt-contentsections/src/class-wpdtrt-contentsections-plugin.php on line 19 [01:28:10] 'phpunit' errored after 887 ms

Explanation

Background

Some generated plugins have other generated plugins as dependencies.

For example:

  • wpdtrt-anchorlinks depends on wpdtrt-contentsections
  • wpdtrt-gallery depends on wpdtrt-contentsections
  • wpdtrt-weather depends on wpdtrt-exif

In a normal WordPress environment, each plugin would be loaded separately (DTRT WordPress Plugin Boilerplate uses TGMPA to manage this). In the WordPress test environment, each plugin is also loaded separately, via test/bootstrap.php. Dependencies are also loaded here, to test compatibility.

Cause

From Composer's perspective, there is only one vendor folder for the plugin package and only one version of DTRT WordPress Plugin Boilerplate can be installed in here.

Normally this works fine, because each plugin is its own package, with its own dependencies and vendor folder. It bundles its own copy of DTRT WordPress Plugin Boilerplate, and so can use whichever version it requires.

But in the test environment, the dependee (wpdtrt-anchorlinks or wpdtrt-gallery) is the plugin package. Its dependents are dependents in the same package - not separate packages with their own vendor folders. They are siblings of DTRT WordPress Plugin Boilerplate and are loaded via bootstrap.php, which loads their WordPress root .php file directly from the Composer vendor folder.

Because Composer can only install one version of each package, it installs the newer version required by the dependee [TODO CHECK], (newer if this was updated first, via gulp version). The dependee also dictates which version of DTRT WordPress Plugin Boilerplate is used, because it is loaded first [TODO CHECK].

This means that the older version required by the dependent is not installed nor available:

Fatal error: Class 'DoTheRightThing\WPPlugin\r_1_4_14\Plugin' not found in /home/travis/build/dotherightthing/wpdtrt-gallery/vendor/dotherightthing/wpdtrt-contentsections/src/class-wpdtrt-contentsections-plugin.php

When the dependent (wpdtrt-contentsections or wpdtrt-exif) is loaded and run, it will not be able to load the version of DTRT WordPress Plugin Boilerplate that is associated with it, if this is older than the version required by the dependee. The only version available is the one required by its dependee. If these versions are not the same, then an error will be thrown and PHPUnit will not be able to continue.

Solution

When bulk updating plugins, update wpdtrt-contentsections and wpdtrt-exif first.

If this is not done, older versions of the dependencies will be locked in. To resolve this, update the lock files of any dependees (wpdtrt-anchorlinks and wpdtrt-gallery), to get the latest changes:

  1. Reset composer.json to remove any local changes
  2. update the composer.lock file with the latest versions of dependencies and download these:
    1. wpdtrt-anchorlinks: run composer update dotherightthing/wpdtrt-contentsections
    2. wpdtrt-gallery: run composer update dotherightthing/wpdtrt-contentsections
    3. wpdtrt-weather: run composer update dotherightthing/wpdtrt-exif
  3. Update the dependee version in package.json
  4. Update all versioned files: yarn run version

If this fails to resolve the problem, check that Private Packagist has the most recent copy. This information is pushed from Github to Private Packagist on git push, via a webhook.