In I2df0f7ea3a, I tried to move an extension service to
MediaWikiServices which is conditionally available depending on configuration: unless the
WBQualityConstraintsSparqlEndpoint configuration setting has been set to a value other than its default
'', the service is not available, and all the classes that get such a service injected deal with this by checking whether it is
null before using it.
However, this resulted in a test failure from a MediaWiki core test:
MediaWikiServicesTest::testDefaultServiceInstantiation asserts that the value returned by the wiring function is an
object, which is not true for the
null value which this wiring function returns by default.
Is it possible to have a service that is possibly
null? (I found one such service using MediaWiki code search, in GoogleLogin’s
ServiceWiring.php, but that might also be a bug.) And in that case, should the core test be updated to allow that?
Otherwise, how should I proceed? The best working solution I can see so far would be to define a “dummy” version of the class and return that if the service is not configured, but then all the classes which get the service injected would have to check whether their injected service is an instance of the dummy class or not, which seems ugly. (For at least one class,
FormatChecker, there is no possible implementation of the dummy that would allow the class to call the service unconditionally, without caring whether it’s real or a dummy.)