cache = new KeyValueCache([KeyValueCache::OPTION_PERSISTENCE => 'unittest']); $serviceLocator = $this->getServiceLocatorMock([ PersistenceManager::SERVICE_ID => $this->getKeyValueMock('unittest') ]); $this->cache->setServiceLocator($serviceLocator); } public function testGet() { $this->assertEquals(null, $this->cache->get('key1')); $this->assertEquals('def', $this->cache->get('key1', 'def')); } public function testSet() { $this->assertEquals(null, $this->cache->get('key1')); $this->assertEquals(true, $this->cache->set('key1', 'value1')); $this->assertEquals('value1', $this->cache->get('key1')); $this->assertEquals('value1', $this->cache->get('key1', 'otherValue')); } public function testDelete() { $this->assertEquals(12, $this->cache->get('key1', 12)); $this->assertEquals(true, $this->cache->set('key1', 'value1')); $this->assertEquals('value1', $this->cache->get('key1')); $this->assertEquals(true, $this->cache->delete('key1')); $this->assertEquals(12, $this->cache->get('key1', 12)); } public function testClear() { $this->assertEquals(true, $this->cache->set('key1', 'value1')); $this->assertEquals(true, $this->cache->set(12, 34)); $this->assertEquals('value1', $this->cache->get('key1')); $this->assertEquals(34, $this->cache->get(12)); $this->assertEquals(true, $this->cache->clear()); $this->assertEquals(null, $this->cache->get('key1')); $this->assertEquals(null, $this->cache->get(12)); } public function testHas() { $this->assertEquals(false, $this->cache->has('key1')); $this->assertEquals(false, $this->cache->has(12)); $this->assertEquals(true, $this->cache->set('key1', 'value1')); $this->assertEquals(true, $this->cache->has('key1')); $this->assertEquals(true, $this->cache->set(12, 34)); $this->assertEquals(true, $this->cache->has(12)); } public function testMultiple() { $this->assertEquals(['1' => null, '2' => null], $this->cache->getMultiple(['1', '2'])); $this->assertEquals(['1' => 'a', '2' => 'a'], $this->cache->getMultiple(['1', '2'], 'a')); $this->assertEquals(true, $this->cache->set('1', 'value1')); $this->assertEquals(['1' => 'value1', '2' => 'a'], $this->cache->getMultiple(['1', '2'], 'a')); $this->assertEquals(true, $this->cache->setMultiple(['2' => 'v2', '3' => 'v3'])); $this->assertEquals(['1' => 'value1', '2' => 'v2', '3' => 'v3'], $this->cache->getMultiple(['1', '2', '3'])); $this->assertEquals(true, $this->cache->deleteMultiple(['1', '3'])); $this->assertEquals(['1' => 'x', '2' => 'v2', '3' => 'x'], $this->cache->getMultiple(['1', '2', '3'], 'x')); $this->assertEquals(false, $this->cache->has(1)); $this->assertEquals(true, $this->cache->has(2)); $this->assertEquals(false, $this->cache->has(3)); } }