5

I have added some phpunit tests to my custom module. When trying to run them in I get this error: Class '\Drupal\Tests\DocumentElement' not found I have copied core/phpunit.xml.dist to core/phpunit.xml and edited the URL and DB values but nothing else.

The command I'm running is vendor/bin/phpunit -c web/core/phpunit.xml web/modules/contrib/my_module/.

It seems that the classloader is not working. What have I missed?

I'm using drupal 9 and phpunit 9. I've also tried with phpunit 7 and 8 but I get the same error.

2 Answers 2

7

Finally got to the bottom of this! The package drupal/core-dev is required.

composer require --dev drupal/core-dev

This installs the package as a development dependency.

2
  • Simple, but if you forgot about this as I did just now, can be frustrating! Jul 15, 2022 at 9:52
  • composer require drupal/core-dev Apr 5 at 14:25
-1

Drupal forgot to add few dependency libraries.

See you have these 2 libraries.

composer show symfony/phpunit-bridge 
composer show phpspec/prophecy-phpunit

If you don't please install.

I also noticed that following library also essential.

behat/mink
1
  • Those are dependencies for drupal/core-dev. If you need them, you need drupal/core-dev.
    – apaderno
    May 9 at 16:43

Your Answer

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

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