Manual:PHP unit testing/Getting started

Jump to navigation Jump to search
Translate this page; This page contains changes which are not marked for translation.
Other languages:
English • ‎français • ‎polski • ‎日本語
MediaWiki Flower
« Unit testing
PHPUnit testing

Core MediaWiki PHP unit tests are in the tests/phpunit directory. Extensions often have tests in a tests/ subdirectory.

  1. Install PHPUnit using the MediaWiki PHPUnit installer (Note: only works for Unix-like operating systems, such as Ubuntu, Mac OS X, Linux, etc.)
    cd tests/phpunit
    sudo ./
  2. Run the tests. The --testdox option produces a nicer output, with checkboxes, where an unchecked box ([ ]) means the test failed.
    php phpunit.php --testdox
  3. Restricting the tests:
    by file:
    php phpunit.php --testdox <path/to/fileTest.php> # Usually it's enough to simply append "Test" to the filename.[1]
    by folder:
    php phpunit.php --testdox <path/to/directory/>
    by group:
    make list-groups
    php phpunit.php --testdox --group <group-name>
    by target:
    make help # list available targets
    make <target-name> # run the chosen target

  1. In general, the directory structure of tests/ roughly matches that of the code being tested. For instance, the tests for includes/utils/IP.php are in tests/phpunit/includes/utils/IPTest.php.