...
Code Block |
---|
php test/phpunit/phpunit.php init |
If you are using the /wiki/spaces/IN/pages/108151852, you can instead run installunit
or install_phpunit
commands in your PHP container.
Step 2: Configure whitelists
...
Add the following whitelist configuration to your phpunit.xml
file directly after the closing </php>
tag. Adjust the paths to match your project’s structure. Only directories and files included in the whitelist will appear in the coverage report.
...
File: test/phpunit/phpunit.xml
Code Block | ||
---|---|---|
| ||
</php>
...
<source>
<include>
<directory suffix=".php">/var/www/totara/src/SITENAME/server/totara/core/classes/local</directory>
<directory suffix=".php">/var/www/totara/src/SITENAME/server/totara/core/classes/task</directory>
<file>/var/www/totara/src/SITENAME/server/totara/core/classes/visibility_adviser.php</file>
</include>
</source> |
...
pcov is a high-performance alternative to XDebug. To set it up:
Install pcov :
Code Block pecl install pcov
Note and note the generated path to
pcov.so
, e.g./usr/local/lib/php/extensions/no-debug-non-zts-20230831/pcov.so
.:Code Block pecl install pcov
Update
php.ini
. Note here also that we update thememory_limit
to 8G:Code Block language ini memory_limit=8G [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
To find your php.ini
’s location, run the following command and see the path in the output:
Code Block |
---|
php --ini |
Generate the report:
Code Block phpunit --coverage-html /var/www/html/coverage_report /path/to/plugin/to/test
Viewing the reportusing Totara docker developer environment
...
Code Block | ||
---|---|---|
| ||
chmod o+rx -R /var/www/totara/src/coverage_report |
You will need to run the above each time you generate a new coverage report.
On your local machine: add your new “coverage_report site” in the hosts file, so that we can access it via the browser. Replace
XX
with the PHP version you are currently using. For example if you’re using PHP 8.3, this will be 83. Once this step has been run, you should not need to repeat this step.
Code Block | ||
---|---|---|
| ||
sudo -- sh -c "echo \"127.0.0.1 coverage_report.totaraXX\" >> /etc/hosts " |
Now you should be able to access your coverage report via the web browser by navigating to
http://coverage_report.totaraXX
, where XX is the PHP version you used in step 2.
...