public function testSetItemAndSetItemsCallSaveWithTtl() { $ttl = rand(); $provider = $this->getMock('Doctrine\\Common\\Cache\\ArrayCache'); $provider->expects($this->exactly(4))->method('save')->with($this->anything(), $this->anything(), $ttl); $this->storage = new DoctrineCacheStorage($this->options, $provider); $this->options->setTtl($ttl); $this->storage->setItem('key', 'value'); $items = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'); $this->storage->setItems($items); }
public function testClearExpired() { if (!$this->_storage instanceof ClearExpiredInterface) { $this->markTestSkipped("Storage doesn't implement ClearExpiredInterface"); } $capabilities = $this->_storage->getCapabilities(); $ttl = $capabilities->getTtlPrecision(); $this->_options->setTtl($ttl); $this->waitForFullSecond(); $this->assertTrue($this->_storage->setItem('key1', 'value1')); // wait until the first item expired $wait = $ttl + $capabilities->getTtlPrecision(); usleep($wait * 2000000); $this->assertTrue($this->_storage->setItem('key2', 'value2')); $this->assertTrue($this->_storage->clearExpired()); if ($capabilities->getUseRequestTime()) { $this->assertTrue($this->_storage->hasItem('key1')); } else { $this->assertFalse($this->_storage->hasItem('key1', ['ttl' => 0])); } $this->assertTrue($this->_storage->hasItem('key2')); }