ObjectCache is already doing a lot of factory pattern logic like creating instances of the various BagOStuff, this should really be the responsibility of the factory servicet. This patch introduces a proper factory (ObjectCacheFactory) to handle the responsibility of creating various instances of BagOStuff. Since `newFromParams()` is a static function that gets passed in configuration of $wgObjectCaches, that can stay that way (to keep supporting how we do this in prod today). Technical Breaking Change: `ObjectCache::makeLocalServerCache()` now has a parameter and requires it but there are no callers of this method outside MW core hence it is safe to change (and this patch update all callers) to work correctly. Cache prefix is gotten from global state because sometimes at this stage, the services container is not available. Bug: T358346 Change-Id: I3179a387486377c6a575d173f39f82870c49c321
38 lines
851 B
PHP
38 lines
851 B
PHP
<?php
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
use MediaWiki\Logger\Spi;
|
|
use Wikimedia\Stats\StatsFactory;
|
|
|
|
/**
|
|
* @covers ObjectCacheFactory
|
|
*/
|
|
class ObjectCacheFactoryTest extends MediaWikiUnitTestCase {
|
|
private function newObjectCacheFactory() {
|
|
$factory = new ObjectCacheFactory(
|
|
$this->createMock( ServiceOptions::class ),
|
|
$this->createMock( StatsFactory::class ),
|
|
$this->createMock( Spi::class )
|
|
);
|
|
|
|
return $factory;
|
|
}
|
|
|
|
public function testNewObjectCacheFactory() {
|
|
$this->assertInstanceOf(
|
|
ObjectCacheFactory::class,
|
|
$this->newObjectCacheFactory()
|
|
);
|
|
}
|
|
|
|
public function testNewFromParams() {
|
|
$factory = $this->newObjectCacheFactory();
|
|
|
|
$objCache = $factory->newFromParams( [
|
|
'class' => 'HashBagOStuff',
|
|
'args' => [ 'foo', 'bar' ],
|
|
] );
|
|
|
|
$this->assertInstanceOf( HashBagOStuff::class, $objCache );
|
|
}
|
|
}
|