Test suite overview
Semantic MediaWiki uses PHPUnit for automated testing. Tests are divided into two main categories:- Unit tests — verify isolated classes and components without a database or external services
- Integration tests — verify the interplay between components by running a full MediaWiki stack with a live database connection
All tests are required to pass before changes can be merged. New functionality must be accompanied by both unit and integration tests.
Test directory structure
Test suites
Test suites are defined inphpunit.xml.dist. Each suite groups related tests:
| Suite name | Contents |
|---|---|
semantic-mediawiki-unit | All unit test classes across src/ |
semantic-mediawiki-data-model | Data model unit tests |
semantic-mediawiki-integration | Integration tests (excluding import tests) |
semantic-mediawiki-import | MediaWiki import integration tests |
semantic-mediawiki-structure | Structural verification tests |
semantic-mediawiki-check | PHPUnit check runner |
semantic-mediawiki-benchmark | Benchmark tests (excluded from standard runs) |
Running tests
Via Make (from the host)
The simplest way to run the full suite is:Inside the container
Open a shell withmake bash, then run Composer scripts directly:
Via docker exec (from the host)
Run specific suites or classes without entering the container:Writing unit tests
Unit tests live intests/phpunit/ in directories that mirror the src/ layout. Follow the arrange, act, assert pattern and avoid hidden expectations or deep inheritance.
- Use
PHPUnit\Framework\TestCaseas the base class for pure unit tests - Use
MwDBaseUnitTestCaseonly when a MediaWiki database connection is required - Avoid
MediaWikiTestCase— it binds tests tightly to the MediaWiki test environment - Keep each test class focused on a single unit of behaviour
- Use dependency injection in the class under test; inject test doubles (mocks, stubs) in the test
semantic-mediawiki-unit testsuite in phpunit.xml.dist if it lives in a directory not already listed.
Writing integration tests
Integration tests live intests/phpunit/Integration/ and require a live MediaWiki and database stack. They complement unit tests by verifying that components behave correctly together.
A practical workflow for writing an integration test:
Reproduce the behaviour
Find a minimal wiki-text scenario that demonstrates the expected (or broken) behaviour. Wiki-text is the easiest way to drive SMW’s full parsing and storage pipeline.
Write a failing test
Encode the scenario as a JSONScript test file (see below) and confirm it fails before applying any fix.
JSONScript integration tests
The preferred format for integration tests in Semantic MediaWiki is JSONScript — a JSON-based abstraction layer that lets you write test scenarios using wiki-text markup without needing to learn PHPUnit or internal MediaWiki objects. JSONScript files live intests/phpunit/Integration/JSONScript/. Each file defines:
- Pages to create (with wiki-text content)
- Assertions to run against parsed output, stored data, or query results
Code coverage
Generate a coverage report in Clover XML format:coverage/php/coverage.xml. The project publishes coverage data to Codecov on every CI run.
Continuous integration
CI runs on GitHub Actions using the same Docker and Makefile setup as local development. The workflow is defined in.github/workflows/main.yml.
The CI matrix covers:
| MediaWiki | PHP | Database | Status |
|---|---|---|---|
| 1.43 | 8.2 | MariaDB 11.2 | Stable (includes coverage report) |
| 1.43 | 8.3 | MariaDB 11.2 | Stable |
| 1.44 | 8.3 | MariaDB 11.2 | Experimental |
| 1.44 | 8.3 | MariaDB 11.8 | Experimental |
| 1.45 | 8.4 | MariaDB 11.8 | Experimental |
make ci, which calls make install followed by composer test and npm test.
