ATTENTION: The following notes are meant for developers only. If you only want to use this plugin you can fully ignore this file.
See: https://moodledev.io/general/development/tools/phpunit
- Spawn a shell inside your Moodle/php-fpm container and navigate to your
Moodle root directory:
docker exec -it my-moodle-container sh cd /usr/share/nginx/www/moodle/
- Prepare PHPUnit configuration. Add the following lines to your
config.php
:$CFG->phpunit_prefix = 'phpu_'; $CFG->phpunit_dataroot = '/path/to/your/phpunit_moodledata';
- Download composer and install dev dependencies:
wget https://getcomposer.org/download/latest-stable/composer.phar php composer.phar install
- Bootstrap test environment:
php admin/tool/phpunit/cli/init.php --disable-composer
- Run all tests:
vendor/bin/phpunit --colors --testdox
- Run all tests for a single component:
vendor/bin/phpunit --colors --testdox --filter quiz_archiver/*
- Run a single test suite:
vendor/bin/phpunit --colors --testdox mod/quiz/report/archiver/tests/Report_test.php
The configuration for automated test execution via GitHub CI can be found in
.github/workflows/moodle-plugin-ci.yml
. It holds a matrix of all supported
software configurations and runs the tests for each of them.
You need to have xdebug installed and enabled in order to generate coverage reports!
- Run PHPUnit with coverage report:
XDEBUG_MODE=coverage vendor/bin/phpunit --colors --testdox --coverage-html /tmp/coverage --filter quiz_archiver/*
- Copy the generated report to your machin:
docker cp my-moodle-container:/tmp/coverage /tmp/coverage
- Open the report in your browser:
xdg-open /tmp/coverage/index.html