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?

1 Answer 1


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.

  • Thank you very much for this explanation. Would be nice to have a hint to drupal/core-dev at drupal.org/docs/automated-testing/phpunit-in-drupal/…. The core-dev package has installed phpunit 8.5.8, phpspec/prophecy 1.11.1. For now it seems to work. Should I downgrade to the packages you told? Commented Aug 9, 2020 at 10:21
  • I executed the commands I reported in this answer, in a directory I created, and I obtained the same package versions you got. It means they are fine, with the restrictions given from Drupal core.
    – apaderno
    Commented Aug 9, 2020 at 10:52
  • If you install core-dev after having installed your site & modules, shouldn't you install also all dev dependencies for the modules you want to test ?
    – tostinni
    Commented Aug 11, 2020 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.