Score:0

PHPUnit throws error: \Drupal\Tests\DocumentElement class not found

fi flag

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.

Score:0
fi flag

Finally got to the bottom of this! Needed to do composer install drupal/core-dev

vg flag
Simple, but if you forgot about this as I did just now, can be frustrating!
UnsettlingTrend avatar
in flag
composer require drupal/core-dev
Score:-1
ve flag

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
apaderno avatar
us flag
Those are dependencies for *drupal/core-dev*. If you need them, you need *drupal/core-dev*.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.