rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / objectcache / ObjectCacheTest.php
blobf8ce24ec5533286b30e222ec4352aa411e94a57a
1 <?php
3 class ObjectCacheTest extends MediaWikiTestCase {
5 protected function setUp() {
6 // Parent calls ObjectCache::clear() among other things
7 parent::setUp();
9 $this->setCacheConfig();
10 $this->setMwGlobals( [
11 'wgMainCacheType' => CACHE_NONE,
12 'wgMessageCacheType' => CACHE_NONE,
13 'wgParserCacheType' => CACHE_NONE,
14 ] );
17 private function setCacheConfig( $arr = [] ) {
18 $defaults = [
19 CACHE_NONE => [ 'class' => 'EmptyBagOStuff' ],
20 CACHE_DB => [ 'class' => 'SqlBagOStuff' ],
21 CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
22 // Mock ACCEL with 'hash' as being installed.
23 // This makes tests deterministic regardless of APC.
24 CACHE_ACCEL => [ 'class' => 'HashBagOStuff' ],
25 'hash' => [ 'class' => 'HashBagOStuff' ],
27 $this->setMwGlobals( 'wgObjectCaches', $arr + $defaults );
30 /** @covers ObjectCache::newAnything */
31 public function testNewAnythingNothing() {
32 $this->assertInstanceOf(
33 SqlBagOStuff::class,
34 ObjectCache::newAnything( [] ),
35 'No available types. Fallback to DB'
39 /** @covers ObjectCache::newAnything */
40 public function testNewAnythingHash() {
41 $this->setMwGlobals( [
42 'wgMainCacheType' => 'hash'
43 ] );
45 $this->assertInstanceOf(
46 HashBagOStuff::class,
47 ObjectCache::newAnything( [] ),
48 'Use an available type (hash)'
52 /** @covers ObjectCache::newAnything */
53 public function testNewAnythingAccel() {
54 $this->setMwGlobals( [
55 'wgMainCacheType' => CACHE_ACCEL
56 ] );
58 $this->assertInstanceOf(
59 HashBagOStuff::class,
60 ObjectCache::newAnything( [] ),
61 'Use an available type (CACHE_ACCEL)'
65 /** @covers ObjectCache::newAnything */
66 public function testNewAnythingNoAccel() {
67 $this->setMwGlobals( [
68 'wgMainCacheType' => CACHE_ACCEL
69 ] );
71 $this->setCacheConfig( [
72 // Mock APC not being installed (T160519, T147161)
73 CACHE_ACCEL => [ 'class' => 'EmptyBagOStuff' ]
74 ] );
76 $this->assertInstanceOf(
77 SqlBagOStuff::class,
78 ObjectCache::newAnything( [] ),
79 'Fallback to DB if available types fall back to Empty'
83 /** @covers ObjectCache::newAnything */
84 public function testNewAnythingNoAccelNoDb() {
85 $this->overrideMwServices(); // Ensures restore on tear down
86 MediaWiki\MediaWikiServices::disableStorageBackend();
88 $this->setMwGlobals( [
89 'wgMainCacheType' => CACHE_ACCEL
90 ] );
92 $this->setCacheConfig( [
93 // Mock APC not being installed (T160519, T147161)
94 CACHE_ACCEL => [ 'class' => 'EmptyBagOStuff' ]
95 ] );
97 $this->assertInstanceOf(
98 EmptyBagOStuff::class,
99 ObjectCache::newAnything( [] ),
100 'Fallback to none if available types and DB are unavailable'
104 /** @covers ObjectCache::newAnything */
105 public function testNewAnythingNothingNoDb() {
106 $this->overrideMwServices();
107 MediaWiki\MediaWikiServices::disableStorageBackend();
109 $this->assertInstanceOf(
110 EmptyBagOStuff::class,
111 ObjectCache::newAnything( [] ),
112 'No available types or DB. Fallback to none.'