MediaWiki  1.28.3
ObjectCacheTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5  protected function setUp() {
6  // Parent calls ObjectCache::clear() among other things
7  parent::setUp();
8 
9  $this->setCacheConfig();
10  $this->setMwGlobals( [
11  'wgMainCacheType' => CACHE_NONE,
12  'wgMessageCacheType' => CACHE_NONE,
13  'wgParserCacheType' => CACHE_NONE,
14  ] );
15  }
16 
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' ],
26  ];
27  $this->setMwGlobals( 'wgObjectCaches', $arr + $defaults );
28  }
29 
31  public function testNewAnythingNothing() {
32  $this->assertInstanceOf(
35  'No available types. Fallback to DB'
36  );
37  }
38 
40  public function testNewAnythingHash() {
41  $this->setMwGlobals( [
42  'wgMainCacheType' => 'hash'
43  ] );
44 
45  $this->assertInstanceOf(
48  'Use an available type (hash)'
49  );
50  }
51 
53  public function testNewAnythingAccel() {
54  $this->setMwGlobals( [
55  'wgMainCacheType' => CACHE_ACCEL
56  ] );
57 
58  $this->assertInstanceOf(
61  'Use an available type (CACHE_ACCEL)'
62  );
63  }
64 
66  public function txestNewAnythingNoAccel() {
67  $this->setMwGlobals( [
68  'wgMainCacheType' => CACHE_ACCEL
69  ] );
70 
71  $this->setCacheConfig( [
72  // Mock APC not being installed (T160519, T147161)
73  CACHE_ACCEL => [ 'class' => 'EmptyBagOStuff' ]
74  ] );
75 
76  $this->assertInstanceOf(
79  'Fallback to DB if available types fall back to Empty'
80  );
81  }
82 }
const CACHE_ACCEL
Definition: Defines.php:97
txestNewAnythingNoAccel()
ObjectCache::newAnything.
testNewAnythingHash()
ObjectCache::newAnything.
setCacheConfig($arr=[])
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
testNewAnythingAccel()
ObjectCache::newAnything.
static newAnything($params)
Factory function for CACHE_ANYTHING (referenced from DefaultSettings.php)
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
const CACHE_ANYTHING
Definition: Defines.php:93
const CACHE_NONE
Definition: Defines.php:94
setMwGlobals($pairs, $value=null)
const CACHE_DB
Definition: Defines.php:95
testNewAnythingNothing()
ObjectCache::newAnything.