MDL-36701 add composer to phpunit readme
[moodle.git] / lib / phpunit / readme.md
CommitLineData
5bd40408
PS
1PHPUnit testing support in Moodle
2==================================
3
4
6761e62d
PS
5Documentation
6-------------
7* [Moodle Dev wiki](http://docs.moodle.org/dev/PHPUnit)
07c6fa6e
PS
8* [PHPUnit online documentation](http://www.phpunit.de/manual/current/en/)
9* [Composer dependency manager](http://getcomposer.org/)
6761e62d
PS
10
11
07c6fa6e
PS
12Composer installation
13---------------------
14Composer is a new dependency manager for PHP projects.
15It installs PHP libraries into /vendor/ subdirectory inside your moodle dirroot.
16
171. install Composer - http://getcomposer.org/doc/00-intro.md
182. go to your moodle dirroot and execute `php composer.phar install`
19
20
21PEAR installation (not recommended)
22-----------------------------------
23PEAR is a framework and distribution system for reusable PHP components.
24The packages installed via PEAR are available in all PHP projects.
25
3124abe2 261. install PEAR package manager - see [PEAR Manual](http://pear.php.net/manual/en/installation.php)
4e5ff72e 272. install PHPUnit package and phpunit/DbUnit extension - see [PHPUnit installation documentation](http://www.phpunit.de/manual/current/en/installation.html)
3124abe2 283. edit main config.php - add `$CFG->phpunit_prefix` and `$CFG->phpunit_dataroot` - see config-dist.php
07c6fa6e 294. execute `php admin/tool/phpunit/cli/init.php` to initialise the test environment, repeat it after every upgrade or installation of plugins
5bd40408
PS
30
31
32Test execution
33--------------
07c6fa6e
PS
34* execute `vendor/bin/phpunit` (or `phpunit` if you use PEAR) from dirroot directory
35* you can execute a single test case class using class name followed by path to test file `vendor/bin/phpunit core_phpunit_basic_testcase lib/tests/phpunit_test.php`
36* it is also possible to create custom configuration files in xml format and use `vendor/bin/phpunit -c mytestsuites.xml`
5bd40408
PS
37
38
6761e62d
PS
39How to add more tests?
40----------------------
9571db04
PS
411. create `tests` directory in your plugin
422. add `local/mytest/tests/my_test.php` file with `local_my_testcase` class that extends `basic_testcase` or `advanced_testcase`
433. add some test_*() methods
444. execute your new test case `phpunit local_my_testcase local/mytest/tests/my_test.php`
0d8e51a6 455. execute `php admin/tool/phpunit/cli/init.php` to get the plugin tests included in main phpunit.xml configuration file
5bd40408
PS
46
47
6761e62d
PS
48How to convert existing tests?
49------------------------------
5bd40408
PS
501. create new test file in `xxx/tests/yyy_test.php`
512. copy contents of the old test file
523. replace `extends UnitTestCase` with `extends basic_testcase`
3124abe2 534. fix setUp(), tearDown(), asserts, etc.