Merge "Skin: Make skins aware of their registered skin name"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / MapCacheLRUTest.php
1 <?php
2 /**
3 * @group Cache
4 */
5 class MapCacheLRUTest extends PHPUnit_Framework_TestCase {
6 /**
7 * @covers MapCacheLRU::newFromArray()
8 * @covers MapCacheLRU::toArray()
9 * @covers MapCacheLRU::getAllKeys()
10 * @covers MapCacheLRU::clear()
11 */
12 function testArrayConversion() {
13 $raw = [ 'd' => 4, 'c' => 3, 'b' => 2, 'a' => 1 ];
14 $cache = MapCacheLRU::newFromArray( $raw, 3 );
15
16 $this->assertSame( true, $cache->has( 'a' ) );
17 $this->assertSame( true, $cache->has( 'b' ) );
18 $this->assertSame( true, $cache->has( 'c' ) );
19 $this->assertSame( 1, $cache->get( 'a' ) );
20 $this->assertSame( 2, $cache->get( 'b' ) );
21 $this->assertSame( 3, $cache->get( 'c' ) );
22
23 $this->assertSame(
24 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
25 $cache->toArray()
26 );
27 $this->assertSame(
28 [ 'a', 'b', 'c' ],
29 $cache->getAllKeys()
30 );
31
32 $cache->clear( 'a' );
33 $this->assertSame(
34 [ 'b' => 2, 'c' => 3 ],
35 $cache->toArray()
36 );
37
38 $cache->clear();
39 $this->assertSame(
40 [],
41 $cache->toArray()
42 );
43 }
44
45 /**
46 * @covers MapCacheLRU::has()
47 * @covers MapCacheLRU::get()
48 * @covers MapCacheLRU::set()
49 */
50 function testLRU() {
51 $raw = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
52 $cache = MapCacheLRU::newFromArray( $raw, 3 );
53
54 $this->assertSame( true, $cache->has( 'c' ) );
55 $this->assertSame(
56 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
57 $cache->toArray()
58 );
59
60 $this->assertSame( 3, $cache->get( 'c' ) );
61 $this->assertSame(
62 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
63 $cache->toArray()
64 );
65
66 $this->assertSame( 1, $cache->get( 'a' ) );
67 $this->assertSame(
68 [ 'b' => 2, 'c' => 3, 'a' => 1 ],
69 $cache->toArray()
70 );
71
72 $cache->set( 'a', 1 );
73 $this->assertSame(
74 [ 'b' => 2, 'c' => 3, 'a' => 1 ],
75 $cache->toArray()
76 );
77
78 $cache->set( 'b', 22 );
79 $this->assertSame(
80 [ 'c' => 3, 'a' => 1, 'b' => 22 ],
81 $cache->toArray()
82 );
83
84 $cache->set( 'd', 4 );
85 $this->assertSame(
86 [ 'a' => 1, 'b' => 22, 'd' => 4 ],
87 $cache->toArray()
88 );
89
90 $cache->set( 'e', 5, 0.33 );
91 $this->assertSame(
92 [ 'e' => 5, 'b' => 22, 'd' => 4 ],
93 $cache->toArray()
94 );
95
96 $cache->set( 'f', 6, 0.66 );
97 $this->assertSame(
98 [ 'b' => 22, 'f' => 6, 'd' => 4 ],
99 $cache->toArray()
100 );
101
102 $cache->set( 'g', 7, 0.90 );
103 $this->assertSame(
104 [ 'f' => 6, 'g' => 7, 'd' => 4 ],
105 $cache->toArray()
106 );
107
108 $cache->set( 'g', 7, 1.0 );
109 $this->assertSame(
110 [ 'f' => 6, 'd' => 4, 'g' => 7 ],
111 $cache->toArray()
112 );
113 }
114 }