Manual:PHP unit testing/Getting started
< Manual:PHP unit testing(Redirected from PHPunit/TLDR)
Core MediaWiki PHP unit tests are in the tests/phpunit
directory.
Extensions often have tests in a tests/
subdirectory.
- 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
- Run the tests. The
--testdox
option produces a nicer output, with checkboxes, where an unchecked box ([ ]
) means the test failed.php phpunit.php --testdox
- 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
- by file:
- ↑ In general, the directory structure of
tests/
roughly matches that of the code being tested. For instance, the tests forincludes/utils/IP.php
are intests/phpunit/includes/utils/IPTest.php
.