...
pcov is an alternative to XDebug. It is much more performant. For users with VMs or Docker images, these steps each take place within the image.
To get it running:
Install the pcov extension with
When running this command, it will output the path it saved itself in. This will be something likeCode Block pecl install pcov
This command generates a unique path to the pcov.so
file that will need to be copied, e.g. /usr/local/lib/php/extensions/no-debug-non-zts-20230831/pcov.so
Only for Totara 12: Install pcov/clobber which adds pcov support to PHPUnit 7
Code Block composer require pcov/clobber vendor/bin/pcov clobber
Ensure PHP has enough memory in php.ini. Give it heaps, as code coverage is memory intensive.
Code Block memory_limit=8G
Enable and configure the extension in the php.ini
...
. The
...
path/to/pcov.
...
so
will be the one you noted down from step 1.Code Block [pcov] extension="path/to/pcov.so" pcov.enabled=1 pcov.exclude='~(vendor|tests|node_modules|.git|client|.scannerwork)~' pcov.initial.memory=1073741824 pcov.initial.files=30000
Generate the code coverage report
Totara 13 and above
Replace server/path/to/plugin/to/test
with the directory path for the plugin you want to test. For example, if I were . e.g. for generating a code coverage report for Totara hierarchy, this would be use server/totara/hierarchy
.
Code Block |
---|
phpunit --coverage-html /var/www/html/coverage_report /path/to/plugin/to/test |
...
Code Block |
---|
cd /path/to/code XDEBUG_MODE=off php -d pcov.directory=`pwd` vendor/bin/phpunit --filter=totara_core --coverage-html /var/www/html/coverage_report |
This will create a nicely an XML-formatted report for you to inspect, located at /var/www/html/coverage_report
.
...
If using our Totara Docker Development environment - /wiki/spaces/IN/pages/108151852 - you can replace /var/www/html/coverage_report
with /var/www/totara/src/coverage_report
. Once you’ve done this, execute the following steps to make it accessible:
Once the coverage _ report has been created, set the permissions to allow nginx to access the generated files by running the following in your PHP container:
...