...
Install the pcov extension with
Code Block pecl install pcov
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
Code Block [pcov] extension=pcov.so pcov.enabled=1 pcov.exclude='~(vendor|tests|node_modules|.git|client|.scannerwork)~' pcov.initial.memory=1073741824 pcov.initial.files=30000
Ensure PHP has enough memory in php.ini. Give it heaps, as code coverage is memory intensive.
Code Block memory_limit=8G
Generate the code coverage
Totara 13 and above
Code Block cd /path/to/code XDEBUG_MODE=off php -dpconv.directory=`pwd` test/phpunit/phpunit.php run --filter=totara_core --coverage-html /var/www/html/coverage_report
Totara 12
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 formatted report for you to inspect.
...
Code Block |
---|
[pcov]
extension=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
...
, located at /var/www/html/coverage_report
PHPStorm and XDebug/pcov
PHPStorm has the ability to run code coverage anaylsis in product using XDebug or pcov. The analysis is automatically loaded into the platform and displayed both in the Coverage tool, and in-editor when looking at files. Their documentation on code coverage explains how to set it up.
...