Continuous integration/Tutorials/Generating PHP test coverage for a MediaWiki extension

The Wikimedia CI infrastructure supports generating PHP test code coverage for MediaWiki extensions, and publishing reports on https://doc.wikimedia.org/cover-extensions/.

Requirements

 * Your PHP code is in a folder named  or , and in   for scripts.
 * Your PHPUnit tests are in a folder named
 * Your extension installs sucessfully using the SQLite database backend.

Preparing your tests
Your tests will need  tags that tell PHPUnit what code is being covered by the tests. These tags can apply to the whole class, or just for a single test function. They can also apply to an entire class or a specific method. See the PHPUnit documentation for more details.

Note that if you are not extending from, then PHPUnit will not validate the tags until it tries to run and generate coverage. You can use the  trait in your test case to ensure the tags are validated as part of normal tests.

Running locally
First you need to edit  in MediaWiki core to adjust the coverage filter:

Then you can run:

You can then open  in your web browser to view the coverage report. Even if individual tests fail, the coverage report should still get generated.

Running in CI
Jenkins can trigger a build of the extension coverage after a commit is merged in the repository. You'll need to send a patch to the  repository. See 435673 for which jobs need to be added.