diff options
author | Timo Tijhof <krinkle@fastmail.com> | 2023-02-14 21:18:33 +0000 |
---|---|---|
committer | Timo Tijhof <krinkle@fastmail.com> | 2023-02-21 21:31:42 +0000 |
commit | d16eba24df93723a2b78f286b7ea0194be8da56f (patch) | |
tree | 06e7293c920f184236b1f0d6f4af7a0d9fbb1a2c /tests | |
parent | bf342382522dfce37dd86ab99a0b8591dbc523cc (diff) | |
download | mediawikicore-d16eba24df93723a2b78f286b7ea0194be8da56f.tar.gz mediawikicore-d16eba24df93723a2b78f286b7ea0194be8da56f.zip |
objectcache: Move main cache to internal "_LocalClusterCache" service
This is preparation for re-using it in the MainWANObjectCache
service in a way that preserves proper dependency injection.
This is related to a declined task (T243233) which proposed offering
it as a non-internal service. It is expected to remain internal, with
public callers generally migrated to WANObjectCache or WRStats or
in some cases to a (not yet implemented) lock manager service.
Bug: T329680
Change-Id: I8af9667529b4896f17a22b66823e7eac859d4229
Diffstat (limited to 'tests')
-rw-r--r-- | tests/phpunit/MediaWikiIntegrationTestCase.php | 20 | ||||
-rw-r--r-- | tests/phpunit/includes/objectcache/ObjectCacheTest.php | 8 |
2 files changed, 14 insertions, 14 deletions
diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php index c8a9871d96bb..1f35d92a4d52 100644 --- a/tests/phpunit/MediaWikiIntegrationTestCase.php +++ b/tests/phpunit/MediaWikiIntegrationTestCase.php @@ -891,23 +891,25 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { * * @note This will cause any existing service instances to be reset. * - * @param string|BagOStuff $cache - * + * @param string|int|BagOStuff $cache * @return string|int The new value of the MainCacheType setting. */ protected function setMainCache( $cache ) { if ( $cache instanceof BagOStuff ) { - // ObjectCache::$instances is reset after each test by resetNonGlobalServices(). - ObjectCache::$instances[ 'UTCache' ] = $cache; - $cache = 'UTCache'; + $cacheId = 'UTCache'; + ObjectCache::$instances[ $cacheId ] = $cache; + } else { + $cacheId = $cache; + $cache = ObjectCache::getInstance( $cacheId ); } - if ( !is_string( $cache ) && !is_int( $cache ) ) { - throw new InvalidArgumentException( 'Bad type of $cache parameter: ' . get_debug_type( $cache ) ); + if ( !is_string( $cacheId ) && !is_int( $cacheId ) ) { + throw new InvalidArgumentException( 'Bad type of $cache parameter: ' . get_debug_type( $cacheId ) ); } - $this->overrideConfigValue( MainConfigNames::MainCacheType, $cache ); - return $cache; + $this->overrideConfigValue( MainConfigNames::MainCacheType, $cacheId ); + $this->setService( '_LocalClusterCache', $cache ); + return $cacheId; } /** diff --git a/tests/phpunit/includes/objectcache/ObjectCacheTest.php b/tests/phpunit/includes/objectcache/ObjectCacheTest.php index a6477b0ba843..ac3b77f1854f 100644 --- a/tests/phpunit/includes/objectcache/ObjectCacheTest.php +++ b/tests/phpunit/includes/objectcache/ObjectCacheTest.php @@ -62,12 +62,11 @@ class ObjectCacheTest extends MediaWikiIntegrationTestCase { } public function testNewAnythingNoAccel() { - $this->setMainCache( CACHE_ACCEL ); - + // Mock APC not being installed (T160519, T147161) $this->setCacheConfig( [ - // Mock APC not being installed (T160519, T147161) CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ] ] ); + $this->setMainCache( CACHE_ACCEL ); $this->assertInstanceOf( SqlBagOStuff::class, @@ -77,12 +76,11 @@ class ObjectCacheTest extends MediaWikiIntegrationTestCase { } public function testNewAnythingNoAccelNoDb() { - $this->setMainCache( CACHE_ACCEL ); - $this->setCacheConfig( [ // Mock APC not being installed (T160519, T147161) CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ] ] ); + $this->setMainCache( CACHE_ACCEL ); $this->getServiceContainer()->disableStorage(); |