5 class MapCacheLRUTest
extends PHPUnit_Framework_TestCase
{
7 use MediaWikiCoversValidator
;
10 * @covers MapCacheLRU::newFromArray()
11 * @covers MapCacheLRU::toArray()
12 * @covers MapCacheLRU::getAllKeys()
13 * @covers MapCacheLRU::clear()
15 function testArrayConversion() {
16 $raw = [ 'd' => 4, 'c' => 3, 'b' => 2, 'a' => 1 ];
17 $cache = MapCacheLRU
::newFromArray( $raw, 3 );
19 $this->assertSame( true, $cache->has( 'a' ) );
20 $this->assertSame( true, $cache->has( 'b' ) );
21 $this->assertSame( true, $cache->has( 'c' ) );
22 $this->assertSame( 1, $cache->get( 'a' ) );
23 $this->assertSame( 2, $cache->get( 'b' ) );
24 $this->assertSame( 3, $cache->get( 'c' ) );
27 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
37 [ 'b' => 2, 'c' => 3 ],
49 * @covers MapCacheLRU::has()
50 * @covers MapCacheLRU::get()
51 * @covers MapCacheLRU::set()
54 $raw = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
55 $cache = MapCacheLRU
::newFromArray( $raw, 3 );
57 $this->assertSame( true, $cache->has( 'c' ) );
59 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
63 $this->assertSame( 3, $cache->get( 'c' ) );
65 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
69 $this->assertSame( 1, $cache->get( 'a' ) );
71 [ 'b' => 2, 'c' => 3, 'a' => 1 ],
75 $cache->set( 'a', 1 );
77 [ 'b' => 2, 'c' => 3, 'a' => 1 ],
81 $cache->set( 'b', 22 );
83 [ 'c' => 3, 'a' => 1, 'b' => 22 ],
87 $cache->set( 'd', 4 );
89 [ 'a' => 1, 'b' => 22, 'd' => 4 ],
93 $cache->set( 'e', 5, 0.33 );
95 [ 'e' => 5, 'b' => 22, 'd' => 4 ],
99 $cache->set( 'f', 6, 0.66 );
101 [ 'b' => 22, 'f' => 6, 'd' => 4 ],
105 $cache->set( 'g', 7, 0.90 );
107 [ 'f' => 6, 'g' => 7, 'd' => 4 ],
111 $cache->set( 'g', 7, 1.0 );
113 [ 'f' => 6, 'd' => 4, 'g' => 7 ],