PHPUnit: Difference between revisions
| Line 20: | Line 20: | ||
pear install pear.phpunit.de/PHPUnit | pear install pear.phpunit.de/PHPUnit | ||
= | =Initialisation of test environment= | ||
Our PHPUnit integration requires a dedicated database and dataroot. First edit config.php, you need to specify new dataroot directory and prefix, you can find examples in config-dist.php | Our PHPUnit integration requires a dedicated database and dataroot. First edit config.php, you need to specify new dataroot directory and prefix, you can find examples in config-dist.php | ||
Revision as of 12:40, 8 April 2012
Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.
| PHPUnit | |
|---|---|
| Project state | Work in progress |
| Tracker issue | MDL-32323, MDL-32149, MDL-31857 |
| Discussion | see tracker issues |
| Assignee | Petr Škoda (škoďák) |
Moodle 2.3
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.
Installation steps:
- 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:
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 edit config.php, you need to specify new dataroot directory and prefix, 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 database using following commands:
cd /home/example/moodle php admin/tool/phpunit/cli/util.php --drop php admin/tool/phpunit/cli/util.php --install
These commands have to be used also after any upgrade or plugin (un)installation.
Test execution
PHPUnit tests are executed from the command line. PHP IDEs usually have integration options for PHPUnit.
All test suites
Before first execution you should build new configuration file phpunit.xml by executing:
cd /home/example/moodle php admin/tool/phpunit/cli/util.php --buildconfig
To execute all system tests specified in default configuration file run:
cd /home/example/moodle phpunit
Individual tests
cd /home/example/moodle phpunit mod/yourmodule/tests/some_test.php
All tests in one directory
cd /home/example/moodle phpunit mod/yourmodule/tests/*_test.php
Execution from different directory
If you execute phpunit form directory different from your dirroot you need to specify path to configuration file.
cd ~/ phpunit -c /home/example/moodle/phpunit.xml /home/example/moodle/first_test.php
Execution from IDE
In IDEs you may need to specify path to configuration file, use "/home/example/moodle/phpunit.xml".