MediaWiki REL1_28
CachedBagOStuffTest.php
Go to the documentation of this file.
1<?php
2
6class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
7
12 public function testGetFromBackend() {
13 $backend = new HashBagOStuff;
14 $cache = new CachedBagOStuff( $backend );
15
16 $backend->set( 'foo', 'bar' );
17 $this->assertEquals( 'bar', $cache->get( 'foo' ) );
18
19 $backend->set( 'foo', 'baz' );
20 $this->assertEquals( 'bar', $cache->get( 'foo' ), 'cached' );
21 }
22
27 public function testSetAndDelete() {
28 $backend = new HashBagOStuff;
29 $cache = new CachedBagOStuff( $backend );
30
31 for ( $i = 0; $i < 10; $i++ ) {
32 $cache->set( "key$i", 1 );
33 $this->assertEquals( 1, $cache->get( "key$i" ) );
34 $this->assertEquals( 1, $backend->get( "key$i" ) );
35 $cache->delete( "key$i" );
36 $this->assertEquals( false, $cache->get( "key$i" ) );
37 $this->assertEquals( false, $backend->get( "key$i" ) );
38 }
39 }
40
45 public function testWriteCacheOnly() {
46 $backend = new HashBagOStuff;
47 $cache = new CachedBagOStuff( $backend );
48
49 $cache->set( 'foo', 'bar', 0, CachedBagOStuff::WRITE_CACHE_ONLY );
50 $this->assertEquals( 'bar', $cache->get( 'foo' ) );
51 $this->assertFalse( $backend->get( 'foo' ) );
52
53 $cache->set( 'foo', 'old' );
54 $this->assertEquals( 'old', $cache->get( 'foo' ) );
55 $this->assertEquals( 'old', $backend->get( 'foo' ) );
56
57 $cache->set( 'foo', 'new', 0, CachedBagOStuff::WRITE_CACHE_ONLY );
58 $this->assertEquals( 'new', $cache->get( 'foo' ) );
59 $this->assertEquals( 'old', $backend->get( 'foo' ) );
60
61 $cache->delete( 'foo', CachedBagOStuff::WRITE_CACHE_ONLY );
62 $this->assertEquals( 'old', $cache->get( 'foo' ) ); // Reloaded from backend
63 }
64
68 public function testCacheBackendMisses() {
69 $backend = new HashBagOStuff;
70 $cache = new CachedBagOStuff( $backend );
71
72 // First hit primes the cache with miss from the backend
73 $this->assertEquals( false, $cache->get( 'foo' ) );
74
75 // Change the value in the backend
76 $backend->set( 'foo', true );
77
78 // Second hit returns the cached miss
79 $this->assertEquals( false, $cache->get( 'foo' ) );
80
81 // But a fresh value is read from the backend
82 $backend->set( 'bar', true );
83 $this->assertEquals( true, $cache->get( 'bar' ) );
84 }
85}
testCacheBackendMisses()
CachedBagOStuff::doGet.
testSetAndDelete()
CachedBagOStuff::set CachedBagOStuff::delete.
testWriteCacheOnly()
CachedBagOStuff::set CachedBagOStuff::delete.
testGetFromBackend()
CachedBagOStuff::__construct CachedBagOStuff::doGet.
Wrapper around a BagOStuff that caches data in memory.
Simple store for keeping values in an associative array for the current process.
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:37
$cache
Definition mcc.php:33