moodle/lib/phpunit
Petr Skoda a9236a2c3f MDL-45287 fix behat database reset between scenarios
We cannot find out if DB received any writes because behat
web access runs in different request.

This was affecting only scenarios without generators.
2014-04-28 17:02:58 +08:00
..
classes MDL-45287 fix behat database reset between scenarios 2014-04-28 17:02:58 +08:00
tests MDL-44954 messages: Fixed save notifications with the notification flag 2014-04-07 12:19:52 +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