public function test_iterator() { $cache = new LRUCache(10); $cache->put(1, 12345); $cache->put(2, 23456); $cache->put(3, 34567); $cache->put(2, 23457); $expectedOrder = [2 => 23457, 3 => 34567, 1 => 12345]; $actualOrder = []; foreach ($cache as $key => $value) { $actualOrder[$key] = $value; } $this->assertEquals($expectedOrder, $actualOrder, "iterator should iterate in lru order"); }
/** * @param $key string * @param $value \mysqli_stmt * * @return bool */ public function put($key, $value) : bool { $isMysqliStatement = is_a($value, \mysqli_stmt::class); if ($isMysqliStatement) { parent::put($key, $value); } return $isMysqliStatement; }
public function testExists() { $lru = new LRUCache(5); $this->assertFalse($lru->exists('test')); $lru->put('test', false); $this->assertTrue($lru->exists('test')); }