1

I returned to Drupal recently and have some custom modules mostly for hooking into and modifying node data and form elements and validation. There is also a custom migration module for moving data from an old system (once ready each is single use).

I was also recently tasked with integrating the repo with SonarQube, which is done via sonar-scanner in a Jenkins pipeline and PHPUnit. Most of the module functions are contained in .module and .inc files. The examples for using PHPUnit with Drupal modules do not show how to provide test coverage for these types of files and functions.

How would I setup testing for these files and functions? Would this require a major refactor to move to subscribers, but still some hooks have not been migrated. Should these files and functions even be included for coverage?

5
  • Should code be included in test coverage reports? Yes. Is this question how to unit test Drupal modules and generate code coverage reports? Or is the question how to get existing code coverage reports to be seen by SonarQube? I don't understand how SonarQube is particularly relevant to the question if it is the former.
    – cilefen
    Jul 1, 2022 at 18:30
  • 1
    Authoring tests is very well documented, drupal.org/docs/testing/phpunit-in-drupal/…, and running tests with coverage is very well documented: drupal.org/docs/automated-testing/phpunit-in-drupal/…
    – cilefen
    Jul 1, 2022 at 18:35
  • Or is this question, "how to ensure .inc and .module files are included in code coverage reports"? PHPunit has a way to do that if this doesn't already work with the configuration Drupal provides: phpunit.readthedocs.io/en/9.5/…
    – cilefen
    Jul 1, 2022 at 19:02
  • The .module and .inc are included, but I do not see how to properly set up testing for them. All the examples (at least seem to be) in reference of src classes and not the 'hook' methods Jul 1, 2022 at 19:38
  • If it is alter hooks: drupal.stackexchange.com/questions/290703/…
    – cilefen
    Jul 1, 2022 at 19:57

0

Your Answer

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

Browse other questions tagged or ask your own question.