public function testLeastRecentlyUsedShiftForLimitedCacheSize()
 {
     $instance = new FixedInMemoryCache(5);
     $instance->save('berlin', array('berlin'));
     $this->assertEquals(array('berlin'), $instance->fetch('berlin'));
     foreach (array('paris', 'london', '東京', '北京', 'new york') as $city) {
         $instance->save($city, array($city));
     }
     // 'paris' was added and removes 'berlin' from the cache
     $this->assertFalse($instance->fetch('berlin'));
     $stats = $instance->getStats();
     $this->assertEquals(5, $stats['count']);
     // 'paris' moves to the top (last postion as most recently used) and
     // 'london' becomes the next LRU candidate
     $this->assertEquals(array('paris'), $instance->fetch('paris'));
     $instance->save('rio', 'rio');
     $this->assertFalse($instance->fetch('london'));
     // 東京 would be the next LRU slot but setting it again will move it to MRU
     // and push 北京 into the next LRU position
     $instance->save('東京', '東京');
     $instance->save('sidney', 'sidney');
     $this->assertFalse($instance->fetch('北京'));
     $stats = $instance->getStats();
     $this->assertEquals(5, $stats['count']);
 }
 public function testGetDataItemForCachedId()
 {
     $connection = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock();
     $connection->expects($this->never())->method('selectRow');
     $cache = new FixedInMemoryCache();
     $cache->save(42, 'Foo#0##');
     $instance = new DataItemByIdFinder($connection, 'foo', $cache);
     $this->assertInstanceOf('\\SMW\\DIWikiPage', $instance->getDataItemForId(42));
     $stats = $cache->getStats();
     $this->assertEquals(0, $stats['misses']);
     $this->assertEquals(1, $stats['hits']);
 }