Manual:PHP unit testing/Running the tests

Entrypoints for running the tests
We use composer to run PHPUnit tests. If you have not already, run  in the root of the MediaWiki core repository.

All tests
The entry point for integration tests is the  command, that must be run in the MediaWiki directory:

$ composer phpunit:entrypoint -- path/to/my/test

Error "Cannot access the database: Unknown database"
If you get this error you may need to set the environment variable, e.g:

The "--filter" option does not exist
This and similar errors can occur if you omit the  when invoking the Composer script. Make sure to always use the double dash when running the Composer script, to separate Composer and PHPUnit arguments.

Integration tests
These are tests that are contained in  folders. $ composer phpunit:integration -- path/to/my/test

Unit tests
These are tests that are contained in  folders.

Run only 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: $ composer phpunit:entrypoint -- --group Editing

Output format
To see the name of each running test, use 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.