Merge branch 'MDL-69251-311' of https://github.com/snake/moodle into MOODLE_311_STABLE
[moodle.git] / lib / phpunit / readme.md
blob64ec28a68558b5de1aa6166a26e72167574c9bdc
1 PHPUnit testing support in Moodle
2 ==================================
5 Documentation
6 -------------
7 * [Moodle PHPUnit integration](http://docs.moodle.org/dev/PHPUnit)
8 * [Moodle Writing PHPUnit tests](https://docs.moodle.org/dev/Writing_PHPUnit_tests)
9 * [PHPUnit online documentation](http://www.phpunit.de/manual/current/en/)
10 * [Composer dependency manager](http://getcomposer.org/)
13 Composer installation
14 ---------------------
15 Composer is a dependency manager for PHP projects.
16 It installs PHP libraries into /vendor/ subdirectory inside your moodle dirroot.
18 1. install Composer - [http://getcomposer.org/doc/00-intro.md](http://getcomposer.org/doc/00-intro.md)
19 2. install PHUnit and dependencies - go to your Moodle dirroot and execute `php composer.phar install`
22 Configure your server
23 ---------------------
24 You need to create a new dataroot directory and specify a separate database prefix for the test environment,
25 see config-dist.php for more information.
27 * add `$CFG->phpunit_prefix = 'phpu_';` to your config.php file
28 * and `$CFG->phpunit_dataroot = '/path/to/phpunitdataroot';` to your config.php file
31 Initialise the test environment
32 -------------------------------
33 Before first execution and after every upgrade the PHPUnit test environment needs to be initialised,
34 this command also builds the phpunit.xml configuration files.
36 * execute `php admin/tool/phpunit/cli/init.php`
39 Execute tests
40 --------------
41 * execute `vendor/bin/phpunit` from dirroot directory
42 * you can execute a single test case class using class name followed by path to test file `vendor/bin/phpunit lib/tests/phpunit_test.php`
43 * it is also possible to create custom configuration files in xml format and use `vendor/bin/phpunit -c mytestsuites.xml`
46 How to add more tests?
47 ----------------------
48 1. create `tests/` directory in your add-on
49 2. add test file, for example `local/mytest/tests/my_test.php` file with `my_test` class that extends `basic_testcase` or `advanced_testcase`
50 3. set the test class namespace to that of the class being tested
51 4. add some `test_*()` methods
52 5. execute your new test case `vendor/bin/phpunit local/mytest/tests/my_test.php`
53 6. execute `php admin/tool/phpunit/cli/init.php` to get the plugin tests included in main phpunit.xml configuration file
56 Windows support
57 ---------------
58 * use `\` instead of `/` in paths in examples above