MediaWiki defines two kinds of phpunit tests: "integration" tests that require MediaWiki to be initialized, and "unit" tests that doe not require any global state.
Such "unit" tests can set up any global state (such as global variables) that the code under test relies on. However, this is not easily possible when MediaWikiServices::getInstance() is used, see T243515.
Currently, action api modules (subclasses of ApiBase) cannot be used in a "unit" test, because they rely on global state. This forces all tests for api modules, as well as any test that needs ApiMain, to be an "integration" test, which slows them, down a lot.
- Option 1: allow unit tests to set up mock services. See T246907 for some discussion on this.
- Option 2: convert ApiBase and ApiMain to use dependency injection, to the point where they no longer fail due to missing global state when being instantiated without MediaWiki being initialized.