5 class MapCacheLRUTest
extends PHPUnit_Framework_TestCase
{
7 * @covers MapCacheLRU::newFromArray()
8 * @covers MapCacheLRU::toArray()
9 * @covers MapCacheLRU::getAllKeys()
10 * @covers MapCacheLRU::clear()
12 function testArrayConversion() {
13 $raw = [ 'd' => 4, 'c' => 3, 'b' => 2, 'a' => 1 ];
14 $cache = MapCacheLRU
::newFromArray( $raw, 3 );
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' ) );
24 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
34 [ 'b' => 2, 'c' => 3 ],
46 * @covers MapCacheLRU::has()
47 * @covers MapCacheLRU::get()
48 * @covers MapCacheLRU::set()
51 $raw = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
52 $cache = MapCacheLRU
::newFromArray( $raw, 3 );
54 $this->assertSame( true, $cache->has( 'c' ) );
56 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
60 $this->assertSame( 3, $cache->get( 'c' ) );
62 [ 'a' => 1, 'b' => 2, 'c' => 3 ],
66 $this->assertSame( 1, $cache->get( 'a' ) );
68 [ 'b' => 2, 'c' => 3, 'a' => 1 ],
72 $cache->set( 'a', 1 );
74 [ 'b' => 2, 'c' => 3, 'a' => 1 ],
78 $cache->set( 'b', 22 );
80 [ 'c' => 3, 'a' => 1, 'b' => 22 ],
84 $cache->set( 'd', 4 );
86 [ 'a' => 1, 'b' => 22, 'd' => 4 ],
90 $cache->set( 'e', 5, 0.33 );
92 [ 'e' => 5, 'b' => 22, 'd' => 4 ],
96 $cache->set( 'f', 6, 0.66 );
98 [ 'b' => 22, 'f' => 6, 'd' => 4 ],
102 $cache->set( 'g', 7, 0.90 );
104 [ 'f' => 6, 'g' => 7, 'd' => 4 ],
108 $cache->set( 'g', 7, 1.0 );
110 [ 'f' => 6, 'd' => 4, 'g' => 7 ],