Installing Drupal 9 with the drupal/recommended-project Composer package ships without PHPUnit. Why? (In Drupal 8 it is included. The documentation only tells about Drupal 8.)

Which version of PHPUnit should I use? In this post kiamlaluno answered that Drupal 9 supports PHPUnit 8 at the moment; therefore, I think that version 8.5 is OK, isn't it?

I installed PHPUnit 8.5.8 with composer, but when I try to use it, I get this error.

Class "Symfony\Bridge\PhpUnit\SymfonyTestsListener" does not exist.

This post suggest installing symfony/phpunit-bridge, Composer choose version 5.1, but it didn't work, and I got the same error message. Is this a wrong version for Drupal 9 and PHPUnit 8.5.8? It solved the issue commenting out the listener class in phpunit.xml. But I'm not shure if this is the right way.

  1. Is there anywhere a documentation/tutorial for the actual official release of drupal to get PHPUnit running the recommended way?
有帮助吗?

解决方案

drupal/recommended-project doesn't install PHPUnit, which is instead installed with the drupal/core-dev meta-package. For example, if I wanted to install Drupal 9.0.3, including PHPUnit, I would use the following commands.

composer create-project drupal/recommended-project:^9.0 my-project
cd my-project
composer require 'drupal/core-dev:^9.0'

As said in Starting a Site Using Drupal Composer Project Templates / Adding drupal/core-dev, drupal/core-dev still doesn't depend on drupal/core. Specifying a version of drupal/core-dev is necessary to get a version that matches the Drupal core version you are using. Also, if you want to install Drush, you need to first install drupal/core-dev and then drush/drush.

As for the PHPUnit version, drupal/core-dev 9.0.3 requires the following packages.

  • phpspec/prophecy: ^1.7
  • phpunit/phpunit: ^8.4.1
  • symfony/phpunit-bridge: ^4.4

Using more recent version for phpunit/phpunit and symfony/phpunit-bridge hasn't been tested, yet.

For Drupal 8.8.0, drupal/core-dev 8.8.0 requires a version of phpunit/phpunit that matches ^6.5 || ^7, a version of phpspec/prophecy that matches ^1.7, and a version of symfony/phpunit-bridge that matches ^3.4.3. Even with Drupal 8.8.0, installing PHPUnit after installing Drupal core with drupal/recommended-project requires the same steps I described for Drupal 9.

许可以下: CC-BY-SA归因
scroll top