From 1665ea876f039bd03818575ae82c674c7a3e10b8 Mon Sep 17 00:00:00 2001 From: Wandji69 Date: Wed, 5 Jun 2024 19:44:20 +0100 Subject: [PATCH] User objectCacheFactory methods not deprecated ObjectCache methods Bug: T363770 Change-Id: I2335b315bec6a540409492df4891c518640966d5 --- includes/ResourceLoader/ResourceLoader.php | 4 ++-- includes/ServiceWiring.php | 17 ++++++++------- includes/auth/AuthManager.php | 6 ++++-- .../ThrottlePreAuthenticationProvider.php | 5 ++++- includes/auth/Throttler.php | 9 +++++--- includes/cache/FileCacheBase.php | 7 ++++--- includes/filerepo/ThumbnailEntryPoint.php | 5 +++-- includes/jobqueue/JobQueueGroup.php | 6 ++++-- includes/page/WikiPage.php | 3 ++- includes/user/BotPassword.php | 4 ++-- maintenance/resetAuthenticationThrottle.php | 16 +++++++++----- .../phpunit/includes/auth/AuthManagerTest.php | 21 ++++++++++++------- .../includes/site/CachingSiteStoreTest.php | 17 ++++++++++----- .../MediaWikiIntegrationTestCaseTest.php | 14 +++++++------ 14 files changed, 85 insertions(+), 49 deletions(-) diff --git a/includes/ResourceLoader/ResourceLoader.php b/includes/ResourceLoader/ResourceLoader.php index aa2a650d73e..bd00db0bdd4 100644 --- a/includes/ResourceLoader/ResourceLoader.php +++ b/includes/ResourceLoader/ResourceLoader.php @@ -49,7 +49,6 @@ use MediaWiki\WikiMap\WikiMap; use MWExceptionHandler; use MWExceptionRenderer; use Net_URL2; -use ObjectCache; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -521,7 +520,8 @@ class ResourceLoader implements LoggerAwareInterface { DeferredUpdates::addCallableUpdate( function () { $updatesByEntity = $this->depStoreUpdateBuffer; $this->depStoreUpdateBuffer = []; - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance() + ->getObjectCacheFactory()->getLocalClusterInstance(); $scopeLocks = []; $depsByEntity = []; diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 2fccdfdf460..722985cefda 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -493,12 +493,13 @@ return [ $mainConfig->get( MainConfigNames::MainCacheType ) ); + $objectCacheFactory = $services->getObjectCacheFactory(); if ( is_string( $cpStashType ) ) { - $cpStash = $services->getObjectCacheFactory()->getInstance( $cpStashType ); + $cpStash = $objectCacheFactory->getInstance( $cpStashType ); } elseif ( $isMainCacheBad ) { $cpStash = new EmptyBagOStuff(); } else { - $cpStash = ObjectCache::getLocalClusterInstance(); + $cpStash = $objectCacheFactory->getLocalClusterInstance(); } $chronologyProtector = new ChronologyProtector( @@ -655,7 +656,7 @@ return [ // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup $cache = $services->getLocalServerObjectCache(); if ( $cache instanceof EmptyBagOStuff ) { - $cache = ObjectCache::getLocalClusterInstance(); + $cache = $services->getObjectCacheFactory()->getLocalClusterInstance(); } return new CryptHKDF( $secret, $config->get( MainConfigNames::HKDFAlgorithm ), $cache, $context ); @@ -1417,7 +1418,7 @@ return [ 'PageEditStash' => static function ( MediaWikiServices $services ): PageEditStash { return new PageEditStash( - ObjectCache::getLocalClusterInstance(), + $services->getObjectCacheFactory()->getLocalClusterInstance(), $services->getConnectionProvider(), LoggerFactory::getInstance( 'StashEdit' ), $services->getStatsdDataFactory(), @@ -1745,7 +1746,7 @@ return [ return new Pingback( $services->getMainConfig(), $services->getConnectionProvider(), - ObjectCache::getLocalClusterInstance(), + $services->getObjectCacheFactory()->getLocalClusterInstance(), $services->getHttpRequestFactory(), LoggerFactory::getInstance( 'Pingback' ) ); @@ -2082,7 +2083,7 @@ return [ $cache = $services->getLocalServerObjectCache(); if ( $cache instanceof EmptyBagOStuff ) { - $cache = ObjectCache::getLocalClusterInstance(); + $cache = $services->getObjectCacheFactory()->getLocalClusterInstance(); } return new CachingSiteStore( $rawSiteStore, $cache ); @@ -2266,14 +2267,14 @@ return [ $services->getMainConfig()->get( MainConfigNames::TempAccountCreationThrottle ), [ 'type' => 'tempacctcreate', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => $services->getObjectCacheFactory()->getLocalClusterInstance(), ] ), new Throttler( $services->getMainConfig()->get( MainConfigNames::TempAccountNameAcquisitionThrottle ), [ 'type' => 'tempacctnameacquisition', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => $services->getObjectCacheFactory()->getLocalClusterInstance(), ] ) ); diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php index b20eb9d32f4..2bbc90846e2 100644 --- a/includes/auth/AuthManager.php +++ b/includes/auth/AuthManager.php @@ -35,6 +35,7 @@ use MediaWiki\HookContainer\HookContainer; use MediaWiki\HookContainer\HookRunner; use MediaWiki\Languages\LanguageConverterFactory; use MediaWiki\MainConfigNames; +use MediaWiki\MediaWikiServices; use MediaWiki\Page\PageIdentity; use MediaWiki\Permissions\Authority; use MediaWiki\Permissions\PermissionStatus; @@ -258,6 +259,7 @@ class AuthManager implements LoggerAwareInterface { * @param UserFactory $userFactory * @param UserIdentityLookup $userIdentityLookup * @param UserOptionsManager $userOptionsManager + * */ public function __construct( WebRequest $request, @@ -1406,7 +1408,7 @@ class AuthManager implements LoggerAwareInterface { } // Avoid account creation races on double submissions - $cache = \ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); $lock = $cache->getScopedLock( $cache->makeGlobalKey( 'account', md5( $user->getName() ) ) ); if ( !$lock ) { // Don't clear AuthManager::accountCreationState for this code @@ -1907,7 +1909,7 @@ class AuthManager implements LoggerAwareInterface { } // Avoid account creation races on double submissions - $cache = \ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); $lock = $cache->getScopedLock( $cache->makeGlobalKey( 'account', md5( $username ) ) ); if ( !$lock ) { $this->logger->debug( __METHOD__ . ': Could not acquire account creation lock', [ diff --git a/includes/auth/ThrottlePreAuthenticationProvider.php b/includes/auth/ThrottlePreAuthenticationProvider.php index ad4e2278ca9..b393e6137db 100644 --- a/includes/auth/ThrottlePreAuthenticationProvider.php +++ b/includes/auth/ThrottlePreAuthenticationProvider.php @@ -23,6 +23,7 @@ namespace MediaWiki\Auth; use BagOStuff; use MediaWiki\MainConfigNames; +use MediaWiki\MediaWikiServices; use MediaWiki\User\User; /** @@ -59,7 +60,9 @@ class ThrottlePreAuthenticationProvider extends AbstractPreAuthenticationProvide public function __construct( $params = [] ) { $this->throttleSettings = array_intersect_key( $params, [ 'accountCreationThrottle' => true, 'passwordAttemptThrottle' => true ] ); - $this->cache = $params['cache'] ?? \ObjectCache::getLocalClusterInstance(); + $services = MediaWikiServices::getInstance(); + $this->cache = $params['cache'] ?? $services->getObjectCacheFactory() + ->getLocalClusterInstance(); } protected function postInitSetup() { diff --git a/includes/auth/Throttler.php b/includes/auth/Throttler.php index 4d32285ee72..cd3fdd4f9c6 100644 --- a/includes/auth/Throttler.php +++ b/includes/auth/Throttler.php @@ -70,18 +70,21 @@ class Throttler implements LoggerAwareInterface { . implode( ', ', array_keys( $invalidParams ) ) ); } + $services = MediaWikiServices::getInstance(); + $objectCacheFactory = $services->getObjectCacheFactory(); + if ( $conditions === null ) { - $config = MediaWikiServices::getInstance()->getMainConfig(); + $config = $services->getMainConfig(); $conditions = $config->get( MainConfigNames::PasswordAttemptThrottle ); $params += [ 'type' => 'password', - 'cache' => \ObjectCache::getLocalClusterInstance(), + 'cache' => $objectCacheFactory->getLocalClusterInstance(), 'warningLimit' => 50, ]; } else { $params += [ 'type' => 'custom', - 'cache' => \ObjectCache::getLocalClusterInstance(), + 'cache' => $objectCacheFactory->getLocalClusterInstance(), 'warningLimit' => INF, ]; } diff --git a/includes/cache/FileCacheBase.php b/includes/cache/FileCacheBase.php index 6e4d11ddab8..94f6f94cb57 100644 --- a/includes/cache/FileCacheBase.php +++ b/includes/cache/FileCacheBase.php @@ -28,7 +28,6 @@ use MediaWiki\Config\ServiceOptions; use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; use MediaWiki\Request\WebRequest; -use ObjectCache; use Wikimedia\AtEase\AtEase; use Wikimedia\IPUtils; @@ -262,7 +261,8 @@ abstract class FileCacheBase { : IPUtils::sanitizeRange( "$ip/16" ); # Bail out if a request already came from this range... - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory() + ->getLocalClusterInstance(); $key = $cache->makeKey( static::class, 'attempt', $this->mType, $this->mKey, $ip ); if ( !$cache->add( $key, 1, self::MISS_TTL_SEC ) ) { return; // possibly the same user @@ -278,7 +278,8 @@ abstract class FileCacheBase { * @return int */ public function getMissesRecent() { - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory() + ->getLocalClusterInstance(); return self::MISS_FACTOR * $cache->get( $this->cacheMissKey( $cache ) ); } diff --git a/includes/filerepo/ThumbnailEntryPoint.php b/includes/filerepo/ThumbnailEntryPoint.php index 6067afad833..1c0ea82f4dc 100644 --- a/includes/filerepo/ThumbnailEntryPoint.php +++ b/includes/filerepo/ThumbnailEntryPoint.php @@ -48,7 +48,6 @@ use MediaWiki\Status\Status; use MediaWiki\Title\Title; use Message; use MessageSpecifier; -use ObjectCache; use RepoGroup; use UnregisteredLocalFile; use Wikimedia\AtEase\AtEase; @@ -366,7 +365,9 @@ class ThumbnailEntryPoint extends MediaWikiEntryPoint { protected function generateThumbnail( File $file, array $params, $thumbName, $thumbPath ) { $attemptFailureEpoch = $this->getConfig( MainConfigNames::AttemptFailureEpoch ); - $cache = ObjectCache::getLocalClusterInstance(); + $services = MediaWikiServices::getInstance()->getObjectCacheFactory(); + + $cache = $services->getLocalClusterInstance(); $key = $cache->makeKey( 'attempt-failures', $attemptFailureEpoch, diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index fdfd6fa9e02..80eb94b1455 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -20,6 +20,7 @@ use MediaWiki\Deferred\DeferredUpdates; use MediaWiki\Deferred\JobQueueEnqueueUpdate; +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\ReadOnlyMode; use Wikimedia\UUID\GlobalIdGenerator; @@ -75,6 +76,7 @@ class JobQueueGroup { * @param IBufferingStatsdDataFactory $statsdDataFactory * @param WANObjectCache $wanCache * @param GlobalIdGenerator $globalIdGenerator + * */ public function __construct( $domain, @@ -162,7 +164,7 @@ class JobQueueGroup { } } - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); $cache->set( $cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', self::TYPE_ANY ), 'true', @@ -333,7 +335,7 @@ class JobQueueGroup { * @return bool */ public function queuesHaveJobs( $type = self::TYPE_ANY ) { - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); $key = $cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', $type ); $value = $cache->get( $key ); diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 83fd866ae2d..28e34a9b109 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -3024,7 +3024,8 @@ class WikiPage implements Page, PageRecord { if ( $this->getLinksTimestamp() > $this->getTouched() ) { // If a page is uncacheable, do not keep spamming a job for it. // Although it would be de-duplicated, it would still waste I/O. - $cache = ObjectCache::getLocalClusterInstance(); + $services = MediaWikiServices::getInstance()->getObjectCacheFactory(); + $cache = $services->getLocalClusterInstance(); $key = $cache->makeKey( 'dynamic-linksupdate', 'last', $this->getId() ); $ttl = max( $parserOutput->getCacheExpiry(), 3600 ); if ( $cache->add( $key, time(), $ttl ) ) { diff --git a/includes/user/BotPassword.php b/includes/user/BotPassword.php index c67fa99fa02..95c52f3b141 100644 --- a/includes/user/BotPassword.php +++ b/includes/user/BotPassword.php @@ -37,7 +37,6 @@ use MediaWiki\Session\BotPasswordSessionProvider; use MediaWiki\Session\SessionManager; use MediaWiki\Status\Status; use MWRestrictions; -use ObjectCache; use stdClass; use UnexpectedValueException; use Wikimedia\Rdbms\IDatabase; @@ -407,7 +406,8 @@ class BotPassword { if ( $passwordAttemptThrottle ) { $throttle = new Throttler( $passwordAttemptThrottle, [ 'type' => 'botpassword', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => MediaWikiServices::getInstance()->getObjectCacheFactory() + ->getLocalClusterInstance(), ] ); $result = $throttle->increase( $user->getName(), $request->getIP(), __METHOD__ ); if ( $result ) { diff --git a/maintenance/resetAuthenticationThrottle.php b/maintenance/resetAuthenticationThrottle.php index 975d588b20b..79074c472f2 100644 --- a/maintenance/resetAuthenticationThrottle.php +++ b/maintenance/resetAuthenticationThrottle.php @@ -24,6 +24,7 @@ use MediaWiki\Auth\Throttler; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MainConfigNames; +use MediaWiki\MediaWikiServices; use Wikimedia\IPUtils; require_once __DIR__ . '/Maintenance.php'; @@ -113,9 +114,11 @@ class ResetAuthenticationThrottle extends Maintenance { return; } + $objectCacheFactory = $this->getServiceContainer()->getInstance()->getObjectCacheFactory(); + $throttler = new Throttler( $passwordAttemptThrottle, [ 'type' => 'password', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => $objectCacheFactory->getLocalClusterInstance(), ] ); if ( $rawUsername !== null ) { $usernames = $this->getServiceContainer()->getAuthManager() @@ -132,7 +135,7 @@ class ResetAuthenticationThrottle extends Maintenance { $botPasswordThrottler = new Throttler( $passwordAttemptThrottle, [ 'type' => 'botpassword', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => $objectCacheFactory->getLocalClusterInstance(), ] ); // @phan-suppress-next-line PhanPossiblyUndeclaredVariable T240141 $botPasswordThrottler->clear( $username, $ip ); @@ -159,7 +162,8 @@ class ResetAuthenticationThrottle extends Maintenance { } $throttler = new Throttler( $accountCreationThrottle, [ 'type' => 'acctcreate', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => MediaWikiServices::getInstance()->getObjectCacheFactory() + ->getLocalClusterInstance(), ] ); $throttler->clear( null, $ip ); @@ -177,7 +181,8 @@ class ResetAuthenticationThrottle extends Maintenance { } $throttler = new Throttler( $tempAccountCreationThrottle, [ 'type' => 'tempacctcreate', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => MediaWikiServices::getInstance()->getObjectCacheFactory() + ->getLocalClusterInstance(), ] ); $throttler->clear( null, $ip ); @@ -197,7 +202,8 @@ class ResetAuthenticationThrottle extends Maintenance { } $throttler = new Throttler( $tempAccountNameAcquisitionThrottle, [ 'type' => 'tempacctnameacquisition', - 'cache' => ObjectCache::getLocalClusterInstance(), + 'cache' => MediaWikiServices::getInstance()->getObjectCacheFactory() + ->getLocalClusterInstance(), ] ); $throttler->clear( null, $ip ); diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index 12e14331988..a2a1abff711 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -61,7 +61,7 @@ use MediaWiki\Watchlist\WatchlistManager; use MediaWikiIntegrationTestCase; use Message; use MessageSpecifier; -use ObjectCache; +use ObjectCacheFactory; use PHPUnit\Framework\Assert; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\Rule\InvocationOrder; @@ -141,6 +141,9 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { /** @var UserOptionsManager */ private $userOptionsManager; + /** @var ObjectCacheFactory */ + private $objectCacheFactory; + /** * Sets a mock on a hook * @param string $hook @@ -272,7 +275,7 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { $this->getServiceContainer()->getDatabaseBlockStore(), $this->getServiceContainer()->getProxyLookup() ) extends BlockManager -{ + { protected function checkHost( $hostname ) { return '127.0.0.1'; } @@ -312,6 +315,9 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { if ( $regen || !$this->userOptionsManager ) { $this->userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); } + if ( $regen || !$this->objectCacheFactory ) { + $this->objectCacheFactory = $this->getServiceContainer()->getObjectCacheFactory(); + } if ( !$this->logger ) { $this->logger = new TestLogger(); } @@ -334,7 +340,8 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { $this->botPasswordStore, $this->userFactory, $this->userIdentityLookup, - $this->userOptionsManager + $this->userOptionsManager, + $this->objectCacheFactory ); $this->manager->setLogger( $this->logger ); $this->managerPriv = TestingAccessWrapper::newFromObject( $this->manager ); @@ -2052,7 +2059,7 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { $this->request->getSession()->setSecret( AuthManager::ACCOUNT_CREATION_STATE, $session ); $this->hook( 'LocalUserCreated', LocalUserCreatedHook::class, $this->never() ); - $cache = ObjectCache::getLocalClusterInstance(); + $cache = $this->objectCacheFactory->getLocalClusterInstance(); $lock = $cache->getScopedLock( $cache->makeGlobalKey( 'account', md5( $username ) ) ); $ret = $this->manager->continueAccountCreation( [] ); unset( $lock ); @@ -2882,7 +2889,7 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { $session->clear(); $user = User::newFromName( $username ); $this->hook( 'LocalUserCreated', LocalUserCreatedHook::class, $this->never() ); - $cache = ObjectCache::getLocalClusterInstance(); + $cache = $this->objectCacheFactory->getLocalClusterInstance(); $lock = $cache->getScopedLock( $cache->makeGlobalKey( 'account', md5( $username ) ) ); $ret = $this->manager->autoCreateUser( $user, AuthManager::AUTOCREATE_SOURCE_SESSION, true, true ); unset( $lock ); @@ -2949,7 +2956,7 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { ); // Test backoff - $cache = ObjectCache::getLocalClusterInstance(); + $cache = $this->objectCacheFactory->getLocalClusterInstance(); $backoffKey = $cache->makeKey( 'AuthManager', 'autocreate-failed', md5( $username ) ); $cache->set( $backoffKey, true ); $session->clear(); @@ -2988,7 +2995,7 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase { $this->assertSame( null, $session->get( AuthManager::AUTOCREATE_BLOCKLIST ) ); // Test addToDatabase throws an exception - $cache = ObjectCache::getLocalClusterInstance(); + $cache = $this->objectCacheFactory->getLocalClusterInstance(); $backoffKey = $cache->makeKey( 'AuthManager', 'autocreate-failed', md5( $username ) ); $this->assertFalse( $cache->get( $backoffKey ) ); $session->clear(); diff --git a/tests/phpunit/includes/site/CachingSiteStoreTest.php b/tests/phpunit/includes/site/CachingSiteStoreTest.php index 36df5eaea60..4ca2cc07c79 100644 --- a/tests/phpunit/includes/site/CachingSiteStoreTest.php +++ b/tests/phpunit/includes/site/CachingSiteStoreTest.php @@ -2,6 +2,7 @@ namespace MediaWiki\Tests\Site; +use MediaWiki\MediaWikiServices; use MediaWiki\Site\CachingSiteStore; use MediaWiki\Site\HashSiteStore; use MediaWiki\Site\MediaWikiSite; @@ -9,7 +10,6 @@ use MediaWiki\Site\Site; use MediaWiki\Site\SiteList; use MediaWiki\Site\SiteStore; use MediaWikiIntegrationTestCase; -use ObjectCache; /** * @covers \MediaWiki\Site\CachingSiteStore @@ -21,10 +21,12 @@ class CachingSiteStoreTest extends MediaWikiIntegrationTestCase { public function testGetSites() { $testSites = TestSites::getSites(); + $services = MediaWikiServices::getInstance(); $store = new CachingSiteStore( $this->getHashSiteStore( $testSites ), - ObjectCache::getLocalClusterInstance() + $services->getObjectCacheFActory() + ->getLocalClusterInstance() ); $sites = $store->getSites(); @@ -44,8 +46,10 @@ class CachingSiteStoreTest extends MediaWikiIntegrationTestCase { } public function testSaveSites() { + $services = MediaWikiServices::getInstance(); $store = new CachingSiteStore( - new HashSiteStore(), ObjectCache::getLocalClusterInstance() + new HashSiteStore(), + $services->getObjectCacheFActory()->getLocalClusterInstance() ); $sites = []; @@ -77,6 +81,8 @@ class CachingSiteStoreTest extends MediaWikiIntegrationTestCase { $dbSiteStore->method( 'getSite' ) ->willReturn( $this->getTestSite() ); + $services = MediaWikiServices::getInstance()->getObjectCacheFactory(); + $dbSiteStore->method( 'getSites' ) ->willReturnCallback( function () { $siteList = new SiteList(); @@ -85,7 +91,7 @@ class CachingSiteStoreTest extends MediaWikiIntegrationTestCase { return $siteList; } ); - $store = new CachingSiteStore( $dbSiteStore, ObjectCache::getLocalClusterInstance() ); + $store = new CachingSiteStore( $dbSiteStore, $services->getLocalClusterInstance() ); // initialize internal cache $this->assertGreaterThan( 0, $store->getSites()->count(), 'count sites' ); @@ -111,8 +117,9 @@ class CachingSiteStoreTest extends MediaWikiIntegrationTestCase { } public function testClear() { + $services = MediaWikiServices::getInstance()->getObjectCacheFactory(); $store = new CachingSiteStore( - new HashSiteStore(), ObjectCache::getLocalClusterInstance() + new HashSiteStore(), $services->getLocalClusterInstance() ); $this->assertTrue( $store->clear() ); diff --git a/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php b/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php index 6b53e75e293..eb401a3bb4a 100644 --- a/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php @@ -85,7 +85,7 @@ class MediaWikiIntegrationTestCaseTest extends MediaWikiIntegrationTestCase { public function testObjectCache() { $this->assertSame( 'hash', $this->getServiceContainer()->getMainConfig()->get( MainConfigNames::MainCacheType ) ); - $this->assertInstanceOf( HashBagOStuff::class, ObjectCache::getLocalClusterInstance() ); + $this->assertInstanceOf( HashBagOStuff::class, $this->getServiceContainer()->getObjectCacheFactory()->getLocalClusterInstance() ); $this->assertInstanceOf( HashBagOStuff::class, $this->getServiceContainer()->getObjectCacheFactory()->getLocalServerInstance() ); $this->assertInstanceOf( HashBagOStuff::class, $this->getServiceContainer()->getObjectCacheFactory()->getInstance( CACHE_ANYTHING ) ); $this->assertInstanceOf( HashBagOStuff::class, $this->getServiceContainer()->getObjectCacheFactory()->getInstance( CACHE_ACCEL ) ); @@ -213,27 +213,29 @@ class MediaWikiIntegrationTestCaseTest extends MediaWikiIntegrationTestCase { public function testSetMainCache() { // Cache should be set to a hash by default. - $this->assertInstanceOf( HashBagOStuff::class, ObjectCache::getLocalClusterInstance() ); + $this->assertInstanceOf( HashBagOStuff::class, $this->getServiceContainer() + ->getObjectCacheFactory()->getLocalClusterInstance() ); // Use HashBagOStuff. $this->setMainCache( CACHE_HASH ); - $cache = ObjectCache::getLocalClusterInstance(); + $cache = $this->getServiceContainer()->getObjectCacheFactory()->getLocalClusterInstance(); $this->assertInstanceOf( HashBagOStuff::class, $cache ); // Install different HashBagOStuff $cache = new HashBagOStuff(); $name = $this->setMainCache( $cache ); - $this->assertSame( $cache, ObjectCache::getLocalClusterInstance() ); + $this->assertSame( $cache, $this->getServiceContainer()->getObjectCacheFactory()->getLocalClusterInstance() ); $this->assertSame( $cache, $this->getServiceContainer()->getObjectCacheFactory()->getInstance( $name ) ); // Our custom cache object should not replace an existing entry. $this->assertNotSame( $cache, $this->getServiceContainer()->getObjectCacheFactory()->getInstance( CACHE_HASH ) ); $this->setMainCache( CACHE_HASH ); - $this->assertNotSame( $cache, ObjectCache::getLocalClusterInstance() ); + $this->assertNotSame( $cache, $this->getServiceContainer()->getObjectCacheFactory()->getLocalClusterInstance() ); // We should be able to disable the cache. $this->assertSame( CACHE_NONE, $this->setMainCache( CACHE_NONE ) ); - $this->assertInstanceOf( EmptyBagOStuff::class, ObjectCache::getLocalClusterInstance() ); + $this->assertInstanceOf( EmptyBagOStuff::class, $this->getServiceContainer() + ->getObjectCacheFactory()->getLocalClusterInstance() ); } public function testOverrideMwServices() {