Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / libs / objectcache / ReplicatedBagOStuffTest.php
1 <?php
2
3 class ReplicatedBagOStuffTest extends \MediaWikiUnitTestCase {
4 /** @var HashBagOStuff */
5 private $writeCache;
6 /** @var HashBagOStuff */
7 private $readCache;
8 /** @var ReplicatedBagOStuff */
9 private $cache;
10
11 protected function setUp() {
12 parent::setUp();
13
14 $this->writeCache = new HashBagOStuff();
15 $this->readCache = new HashBagOStuff();
16 $this->cache = new ReplicatedBagOStuff( [
17 'writeFactory' => $this->writeCache,
18 'readFactory' => $this->readCache,
19 ] );
20 }
21
22 /**
23 * @covers ReplicatedBagOStuff::set
24 */
25 public function testSet() {
26 $key = 'a key';
27 $value = 'a value';
28 $this->cache->set( $key, $value );
29
30 // Write to master.
31 $this->assertEquals( $value, $this->writeCache->get( $key ) );
32 // Don't write to replica. Replication is deferred to backend.
33 $this->assertFalse( $this->readCache->get( $key ) );
34 }
35
36 /**
37 * @covers ReplicatedBagOStuff::get
38 */
39 public function testGet() {
40 $key = 'a key';
41
42 $write = 'one value';
43 $this->writeCache->set( $key, $write );
44 $read = 'another value';
45 $this->readCache->set( $key, $read );
46
47 // Read from replica.
48 $this->assertEquals( $read, $this->cache->get( $key ) );
49 }
50
51 /**
52 * @covers ReplicatedBagOStuff::get
53 */
54 public function testGetAbsent() {
55 $key = 'a key';
56 $value = 'a value';
57 $this->writeCache->set( $key, $value );
58
59 // Don't read from master. No failover if value is absent.
60 $this->assertFalse( $this->cache->get( $key ) );
61 }
62 }