The problem
When trying to run PHPUnit tests on the MongoDB contrib module for the soon-ready 8.2.0 version, I recently starting encountering this error:
OK, no big deal, let's just run that command.
Hmm, so I need that command but it is not defined in composer.json
. So where is it ?
So that command is referenced in multiple places, but defined nowhere. What's going on ?
The diagnostic
Most of the time, when building Drupal 8 projects, we want to use the drupal-project package, to get a saner project layout. But when contributing to core, the common practice has long been to use either drupal/drupal
or even just a Git checkout of Drupal itself. Things are likely to change on that front when issue #2982674 is fixed, though.
At the same time, PHP versions continue moving, with the now-current version being PHP 7.1.x for most cases, and PHP 7.2.x the target version for this autumn. And PHPunit 4.x, which served us faithfully for years, is not compatible at all with PHP 7.2, so the migration to PHPunit 6.x has been required since Issue #2927806 in april 2018. And is now used for 7.0.x/7.1.x too as detailed in https://www.drupal.org/node/2957906.
But on the other hand, composer-project/drupal-project
provides a composer.json
script which does not include the drupal-phpunit-upgrade
, arguably because it still generates a Drupal 8.5.x version these days, which causes this command to fail.
The expected non-working fix
Until issue #2982674 makes it, or drupal-scaffold
is updated, what we should just need here is the command as it appears in the composer.json
for current Drupal core 8.7.x:
Let's just add it to composer.json
and check PHPunit: still version 4.8.x ! The problem is that composer-project
adds a phpunit dependency to 4.8.36, which installed and locked earlier versions, for which Composer cannot find an update path.
The actual fix
Actually, projects do no longer need this line, because of the webflo/drupal-core-require-dev
dependency, which itself requires phpunit/phpunit (^4.8.35 || ^6.5)
, which would allow PHPunit 6.x, unlike what our base composer.json
requires. So let's just remove the direct dependency on PHPunit currently locking us to 4.8.
As these results show, we now have a PHPunit 6.x, thanks to webflo's package. Problem solved.
Thank you so much, removing…
Thank you so much, removing the direct dependency to phpunit was exacly what I needed.