|Project state||Work in progress|
|Tracker issue||MDL-32323, MDL-32149, MDL-31857|
|Assignee||Petr Škoda (škoďák)|
PHPUnit by Sebastian Bergmann is the most advanced unit testing framework for PHP.
Installation of PHPUnit support
PHPUnit is distributed as PEAR package, it is not part of Moodle installation. You have to manually install it on your dev computer. The installation procedure depends on your operating system or the way you installed PHP.
- install or enable PEAR support in your PHP, see official PEAR installation guide
- upgrade PEAR, in *nix usually
sudo pear upgrade PEAR
- install PHPUnit package as root or Windows administrator (minimum required version is 3.6.0):
pear config-set auto_discover 1 pear install pear.phpunit.de/PHPUnit
Initialisation of test environment
Our PHPUnit integration requires a dedicated database and dataroot. First add new dataroot directory and prefix into your config.php, you can find examples in config-dist.php
$CFG->phpunit_prefix = 'phpu_'; $CFG->phpunit_dataroot = '/home/example/phpu_moodledata';
Then you need to initialise the test environment using following command:
This command has to be used also after any upgrade, plugin (un)installation or adding tests to new plugin.
Test executionTo execute all test suites from main configuration file execute
phpunitscript from your
cd /home/example/moodle phpunit
Use relative path to the test file for execution of one test only:
cd /home/example/moodle phpunit lib/tests/phpunit_test.php
To execute all tests from one directory type:
cd /home/example/moodle phpunit lib/tests/*_test.phpIn IDEs you may need to specify path to configuration file, use absolute path to