Autoload helper classes in tests/src/ for phpunit in contrib module

I am working on a contrib module with phpunit tests.

Currently there is no composer.json or phpunit.xml or installation routine in the module itself, instead one has to run the functional and browser tests from a custom drupal site, where the module is installed in web/modules/contrib/*. So far this works.

Now I want to use helper classes in tests/src/Helper/, in namespace "Drupal\Tests\$modulename\Helper\" and possibly elsewhere.

However, I noticed that drupal_phpunit_get_extension_namespaces() only registers some select namespaces within "Drupal\Tests\$modulename\", instead of the entire namespace.

My questions:

  • Why does Drupal phpunit integration behave this way, instead of registering the entire tests/src/ namespace directory?
  • What is a good way to register the entire tests/src/ directory in the class loader? I still want to be able to run the tests from Drupal installation outside the module itself.

EDIT: New issue on drupal.org: #3258817: Why don’t we register all of /tests/src/ for class loading?


Go to Source of this post
Author Of this post: donquixote
Title Of post: Autoload helper classes in tests/src/ for phpunit in contrib module
Author Link: {authorlink}