PHPUnit: Difference between revisions
sam marshall (talk | contribs) m (→Windows) |
sam marshall (talk | contribs) |
||
Line 30: | Line 30: | ||
* 'Do not setup a web server' | * 'Do not setup a web server' | ||
* In the list of features, | * In the list of features, do not turn on 'PEAR install' (under Extras, defaults to off). It does not work. | ||
=Installation of PHPUnit support= | =Installation of PHPUnit support= |
Revision as of 11:57, 18 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 | [1] |
Assignee | Petr Škoda (škoďák) |
Moodle 2.3
PHPUnit by Sebastian Bergmann is the most advanced unit testing framework for PHP.
Installing PHP
You need to install PHP on your own computer. If you already have it installed you can skip this stage.
Real operating systems
(No instructions, you need to figure this out yourself then add it in here.)
Windows
Do not install PHP 5.4 as there is no installer. Instead, you have to use PHP 5.3.
You probably want the thread-safe version.
While going through the installation, you probably want the following options:
- 'Do not setup a web server'
- In the list of features, do not turn on 'PEAR install' (under Extras, defaults to off). It does not work.
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 (minimum required version is 3.6.0):
pear config-set auto_discover 1 pear install pear.phpunit.de/PHPUnit pear install phpunit/DbUnit
Windows
TODO
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
.
Running tests via web
Although the recommended method is the command line, for cases when you want to run tests on a remote server and do not have command-line access, you can also run tests via the web:
admin/tool/phpunit/webrunner.php
This is a 'secret' feature and may not be well supported.