PHPUnit: Difference between revisions
Line 58: | Line 58: | ||
* read [http://www.phpunit.de/manual/current/en/ official PHPUnit online documentation] | * read [http://www.phpunit.de/manual/current/en/ official PHPUnit online documentation] | ||
* read Moodle [[PHPUnit integration]] page | * read Moodle [[PHPUnit integration]] page | ||
* read [[SimpleTest conversion]] page | |||
[[Category:Unit testing]] | [[Category:Unit testing]] |
Revision as of 19:30, 20 April 2012
Moodle 2.3
What is PHPUnit
PHPUnit by Sebastian Bergmann is an advanced unit testing framework for PHP, it is distributed as PEAR package and is not part of Moodle installation. You have to manually install it on your development computer or test server.
Installation of PHPUnit support
The installation procedure depends on your operating system or the way you installed PHP, minimum required version is 3.6.0:
- install or enable PEAR support in your PHP
- upgrade PEAR as root or administrator:
pear upgrade
- install PHPUnit package as root or administrator:
pear config-set auto_discover 1 pear install pear.phpunit.de/PHPUnit pear install phpunit/DbUnit
Detailed instructions:
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:
cd /home/example/moodle php admin/tool/phpunit/cli/init.php
This command has to be used also after any upgrade, plugin (un)installation or adding tests to new plugin.
Test execution
To execute all test suites from main configuration file execute phpunit
script from your $CFG->dirroot
directory:
cd /home/example/moodle phpunit
Use relative path to the test file for execution of one test only (test case classname followed by path to test file):
cd /home/example/moodle phpunit core_phpunit_basic_testcase lib/tests/phpunit_test.php
In IDEs you may need to specify path to configuration file, use absolute path to phpunit.xml
from your $CFG->dirroot
.
There is an alternative script for running of tests via web interface admin/tool/phpunit/webrunner.php
, use it as the last resort only if you can not use command-line interface on your test server. It will most probably break due to permissions problems if you try to execute it both from command-line and from webrunner. This feature is not officially supported.
PHPUnit support in IDEs
What next?
- read official PHPUnit online documentation
- read Moodle PHPUnit integration page
- read SimpleTest conversion page