The GlobalBlocking utility class is used to provide several utility methods which are all static. This is useful for re-useability, but making these methods static is a problem for writing tests as there is no way to isolate, mock or stub static methods using PHPUnit. This means that:
- All tests for methods that use utility methods that call the DB have to be database integration tests, even if the code that called the static method did not otherwise need to be an integration or DB integration test.
- It is much harder to make the utility methods return unexpected or rare values and as such you need to set-up the DB or configuration values to make these conditions occur.
- For complicated and time-intensive static methods (such as applying a global block), calling these methods from multiple places makes multiple tests take longer causing the tests to be overall slower.
- DI cannot be used for the static methods, which means that tests have to override the service in MediaWikiServices and means many of the tests will have to be integration tests to allow access to the service container.
QA Results - Local
AC | Status | Details |
---|---|---|
1 | ✅ | https://phabricator.wikimedia.org/T357385 here |