moodle/lib/phpunit
Petr Škoda 54f1423ecc MDL-44510 support PHPUnit 4.x
The old style PEAR installation is incompatible with PHPUnit 4,
nobody was supposed to use PEAR any more - composer
is the only supported library installation method now.
2014-03-20 17:30:42 +08:00
..
classes MDL-44339 treat unexpected debugging() calls in phpunit tests as errors 2014-03-14 11:43:46 +08:00
tests MDL-41935 attempt to work around random time comparison test failures 2013-10-12 15:53:25 +02:00
bootstrap.php MDL-34347 remove all problematic global text caching 2014-01-14 10:49:23 +08:00
bootstraplib.php MDL-38589 improve missing PHPUnit library hint 2013-03-22 22:47:08 +01:00
lib.php MDL-44510 support PHPUnit 4.x 2014-03-20 17:30:42 +08:00
phpunit.xsd MDL-32323 add schema for phpunit.xml configuration file 2012-04-10 15:27:01 +02:00
readme.md MDL-43515 update phpunit info page 2013-12-30 15:07:27 +08:00

PHPUnit testing support in Moodle

Documentation

Composer installation

Composer is a dependency manager for PHP projects. It installs PHP libraries into /vendor/ subdirectory inside your moodle dirroot.

  1. install Composer - http://getcomposer.org/doc/00-intro.md
  2. install PHUnit and dependencies - go to your Moodle dirroot and execute php composer.phar install --dev

Configure your server

You need to create a new dataroot directory and specify a separate database prefix for the test environment, see config-dist.php for more information.

  • add $CFG->phpunit_prefix = 'phpu_'; to your config.php file
  • and $CFG->phpunit_dataroot = '/path/to/phpunitdataroot'; to your config.php file

Initialise the test environment

Before first execution and after every upgrade the PHPUnit test environment needs to be initialised, this command also builds the phpunit.xml configuration files.

  • execute php admin/tool/phpunit/cli/init.php

Execute tests

  • execute vendor/bin/phpunit from dirroot directory
  • 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
  • it is also possible to create custom configuration files in xml format and use vendor/bin/phpunit -c mytestsuites.xml

How to add more tests?

  1. create tests/ directory in your add-on
  2. add test file, for example local/mytest/tests/my_test.php file with local_my_testcase class that extends basic_testcase or advanced_testcase
  3. add some test_*() methods
  4. execute your new test case vendor/bin/phpunit local_my_testcase local/mytest/tests/my_test.php
  5. execute php admin/tool/phpunit/cli/init.php to get the plugin tests included in main phpunit.xml configuration file

Windows support

  • use \ instead of / in paths in examples above