Manual:PHP unit testing/Running the tests

Entrypoints for running the tests
If you have not already, run  in the root of the MediaWiki core repository.

Wrapper script
We use a wrapper script to run integration tests. The wrapper script  is located in the   directory and is invoked using the PHP command:

$ cd tests/phpunit $ php phpunit.php path/to/my/test

Composer script
Run only run the pure "unit" tests for MediaWiki core and all extensions and skins:

To run specific pure "unit" tests only, use the PHPUnit entrypoint located at

Select by directory or file
Running all tests from all core components and installed extensions may take a while. During development you may want to focus on just a particular test suite or directory of test suites. Pass the directory or file to the phpunit command.

For example, if you're working on a patch that modifies, with a test covering it under  , then you might run the tests like so:

To run tests for a specific extension or skin:

Select by test name
If you're debugging a specific test case and are adding breakpoints or var_dump statements, it may be useful to filter even more closely than by the file, so as to skip past all other invocations of the same underlying code. To do this, use the  option to match substrings of the test name. For example, given a test suite like the following:

You can combine the directory selection with  to run only the second   test case, like so:

Select by group
Each test case can be grouped using the  annotation in the test case file. The group names may look obscure at first, we will describe them later on in the Writing unit tests chapter.

To only run tests in a particular group, use the  option. To find all available groups, run  to print the available test groups. To run a particular test group, pass it to phpunit, for example: tests/phpunit/$ php phpunit.php --group Editing

Output format
To see the name of each running test, uses the TAP format by passing the  option to PHPUnit: Test Anything Protocol

This format is great to filter the output for non passing test. For example with the grep command:

phpunit also provide a kind of checklist that give out a great output for people not familiar with tests or shells: the testdox format:

An unchecked box, means the test failed, such as the one named « RC ns filter association » above.

Database
Integration tests that involve a database are automatically run against a temporary clone of your current wiki's database (the one configured in LocalSettings.php).

Because of this, it is important that the MediaWiki installation being tested has an up to date and correct database, or error messages (such as "TestUser.php: Can't create user on real database") will result.