PHPUnit 7 can be optionally used to run tests with Drupal 8.8+ and PHP 7.1+.
In the DrupalCI testing environment, PHPUnit 6.5 remains the standard version used to run the testing suite; only PHP 7.3+ testing upgrades PHPUnit to version 7.
Projects that need to use PHPUnit ^7 for testing can upgrade via Composer executing
$ composer update phpunit/phpunit symfony/phpunit-bridge phpspec/prophecy symfony/yaml --with-dependencies
Note that the project's root composer.json
should allow PHPUnit to upgrade, so it needs to be changed beforehand in case a constraint exists to limit PHPUnit to ^6.
Custom test autoloaders
If you experience errors like
Fatal error: Uncaught Error: Class 'Drupal\TestTools\PhpUnitCompatibility\RunnerVersion' not found in /data/app/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php on line 15
You are probably using a custom test autoloader. In this instance you'll need to add the Drupal\TestTools
namespace. You can do this by adapting the following code snippet:
$loader->add('Drupal\\TestTools', \Drupal::root() . '/core/tests/Drupal/TestTools');