private function getRepositoryMockTrhowingNotFoundException() { $keyValue = new KeyValue(self::IRRELEVANT_KEY, self::IRRELEVANT_VALUE); $past = time() - 1; $keyValue->setExpirationTimestamp($past); $mock = $this->getMockBuilder(self::KEY_VALUE_REPOSITORY_CLASS)->disableOriginalConstructor()->getMock(); $mock->expects($this->once())->method('findElement')->will($this->throwException(new KeyNotFoundException(self::IRRELEVANT_KEY, self::IRRELEVANT_VALUE))); return $mock; }
private function prepareExpiration($expiration) { if ($expiration != KeyValue::NO_EXPIRE) { $keyValue = new KeyValue('', ''); $keyValue->setExpirationInSeconds($expiration); $expiration = $keyValue->getExpirationTimestamp(); } return $expiration; }
/** * {@inheritDoc} */ public function get($key, $namespace = KeyValue::DEFAULT_NAMESPACE) { $value = $this->getValue($key, $namespace); $effectiveKey = $this->buildKey($key, $namespace); $expiration = $this->redisClient->ttl($effectiveKey); $keyValue = new KeyValue($key, $value, $namespace); if ($expiration !== -1) { $keyValue->setExpirationInSeconds($expiration); } return $keyValue; }
/** * @param KeyValue $keyValue */ public function create(KeyValue $keyValue) { $existentkeyValue = $this->findElementWithNoException($keyValue->getKey(), $keyValue->getNamespace()); if ($existentkeyValue) { $existentkeyValue->setValues($keyValue->getKey(), $keyValue->getValue(), $keyValue->getNamespace(), $keyValue->getExpirationTimestamp()); } else { $this->dm->persist($keyValue); } $this->flush(); }
private function validateExpiration(KeyValue $keyValue) { if ($keyValue->isExpired()) { throw new ExpiredKeyException($keyValue->getKey(), $keyValue->getNamespace()); } }
/** * @test * @dataProvider getExpiredKeyValues */ public function keyValueShouldBeExpired(KeyValue $keyValue) { $this->assertTrue($keyValue->isExpired()); }