Add Code Coverage reporting

Migrated issue

Reported by: cmlara

Related to !253

Problem/Motivation

GItlabCi supports reporting code coverage and displaying it on MR requests.

While 100% code coverage does not mean the code is perfectly tested, it is an initial indicator on changes to determine if code is being exercised, or if a change may remove coverage of existing code.

A sample of changes is available in https://git.drupalcode.org/project/s3fs/-/blob/86c968fc6862d818997cc3d937272e761754444e/.gitlab-ci.yml

The main aspects are:

_PHPUNIT_EXTRA:
    value: --coverage-cobertura $CI_PROJECT_DIR/coverage.xml --coverage-filter $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/ --coverage-text --colors=never

NOTE: with PCOV the module folder experienced issues when symlinked, xdebug is slower, and less supported, but may have better support symlinked paths.

  coverage: /^\s*Lines:\s*\d+.\d+\%/
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura

Note:
This may conflict with some of the changes to make testing parallel, we may need to revert some of that work for Unit and Kernel tests.

Proposed resolution

Add code coverage reporting to the default GitlabCi template

Remaining tasks

Determine if this is something we wish to implement
Patch

Testing:
- Modules without phpunit.xml
- Modules with existing phpunit.xml (decide what to do here, we can do a warning if the file doesn't have what's needed)
- D10 version of a module
- D11 version of a module

User interface changes

Code coverage will be reported on all tests runs and displayed in MR's.

See: https://docs.gitlab.com/ee/ci/testing/test_coverage_visualization.html

Related issue: Issue #3404084

Related issue: Issue #2974911

Related issue: Issue #3442014

Edited by drupalbot