Manual:PHP unit testing/Getting started
Appearance
Contents
- Running the tests
- Generate code coverage
- Writing testable PHP code
- Writing tests
- Continuous integration
- Understanding build failures
- Appendix
(how to help, resources..)
Tools
This page is outdated. |
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/phpunitsudo ./install-phpunit.sh
- Run the tests. The
--testdoxoption 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-groupsphp phpunit.php --testdox --group <group-name>
- by target:
make help # list available targetsmake <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.phpare intests/phpunit/includes/utils/IPTest.php.
