Jump to content

Manual:PHP unit testing/Getting started

From mediawiki.org
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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 ./install-phpunit.sh
  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.