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
yarn run version
- Commit
- Push to Github
- 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 onwpdtrt-contentsections
wpdtrt-gallery
depends onwpdtrt-contentsections
wpdtrt-weather
depends onwpdtrt-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:
- Reset
composer.json
to remove any local changes - update the
composer.lock
file with the latest versions of dependencies and download these:wpdtrt-anchorlinks
: runcomposer update dotherightthing/wpdtrt-contentsections
wpdtrt-gallery
: runcomposer update dotherightthing/wpdtrt-contentsections
wpdtrt-weather
: runcomposer update dotherightthing/wpdtrt-exif
- Update the dependee version in
package.json
- 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.