Page MenuHomePhabricator

Make ViewFactoryTest a proper unit test
Closed, ResolvedPublic

Description

The WikibaseRepo.ViewFactory service wiring uses the ObjectCache::getLocalClusterInstance() function, which means that the unit test for that service wiring actually can’t run without MediaWiki being set up, because ObjectCache::getLocalClusterInstance() uses MediaWiki globals and the default service container.

A solution for this almost certainly requires T243233: MediaWiki should provide a LocalClusterObjectCache service.

See also: T281708, T281710.

To reproduce:

composer phpunit extensions/Wikibase/repo/tests/phpunit/unit/ServiceWiring/ViewFactoryTest.php

Event Timeline

A solution for this almost certainly requires T243233: MediaWiki should provide a LocalClusterObjectCache service.

That task was declined, but in the meantime, the local cluster instance was added to the service container anyway… as a “private” service, with an underscore prefix -.-

ObjectCache.php
public static function getLocalClusterInstance() {
	return MediaWikiServices::getInstance()->get( '_LocalClusterCache' );
}
ServiceWiring.php
'_LocalClusterCache' => static function ( MediaWikiServices $services ): BagOStuff {
	$mainConfig = $services->getMainConfig();
	$id = $mainConfig->get( MainConfigNames::MainCacheType );
	return $services->getObjectCacheFactory()->getInstance( $id );
},

But I still think we can implement this (along with T281708 and T281710). We can either get the _LocalClusterCache service, and just ignore that it’s not public / stable, or we can just copy+paste its three lines of service wiring and get the right cache depending on the main cache type from the ObjectCacheFactory (T358346) ourselves. (And in either case, we could also wrap this in a Wikibase service.)

Change #1036287 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Use ObjectCacheFactory in ViewFactory service wiring

https://gerrit.wikimedia.org/r/1036287

I think it's fine to use the private service in the contexts of tests. If the service gets changed, at least we know the tests should pick it up.

Change #1036287 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Use ObjectCacheFactory in ViewFactory service wiring

https://gerrit.wikimedia.org/r/1036287