Wikibase
MediaWiki Wikibase extension
|
Date: 2020-03-04
accepted
Currently, the RepoHooks
class remains largely untested due to a combination of two factors:
extension.json
or as global variables in the entrypoints e.g. extensions/Wikibase/repo/Wikibase.php:1020, which means we cannot easily refactor the methods to increase testabilityWikibaseRepo
singleton and it's store, which make it harder to test, as there is no way to to inject a mock of WikibaseRepo
without dependency injection.A RFC for enabling dependency injection in hooks is currently under way. However, an interim solution is needed in order to mitigate the amount of untested logic that exists in that file and other places in the codebase.
While reviewing this issue, two initial solutions were considered:
RepoHooks
into a singleton itself, so that when instantiated, we can inject a Mock of WikibaseRepo
instead of using the real deal.WikibaseClient
Which enables us to mock several parts of it (namely the store), and replace the real store by creating an overrideStore
method. See in following:
However, after a discussion, it was decided to implement a middle ground, that would enable us to gradually refactor hooks, rather than a one time big change.
It was decided to adopt an existing pattern in Wikibase repo where each hook handler gets its own singleton class and provides at least four methods:
newFromGlobalSettings
.This class should be placed under the includes/Hooks
directory. An example of this pattern can be seen in: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/574495