Jump to content
MediaWiki

Manual:PHP unit testing/Getting started

From mediawiki.org
Languages:
This page is outdated.
It was written for an older version of MediaWiki and may not apply to the most recent version. If you have checked or updated this page and found the content to be suitable, please remove this notice.

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.

AltStyle によって変換されたページ (->オリジナル) /