コード例 #1
0
 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;
 }
コード例 #2
0
 private function prepareExpiration($expiration)
 {
     if ($expiration != KeyValue::NO_EXPIRE) {
         $keyValue = new KeyValue('', '');
         $keyValue->setExpirationInSeconds($expiration);
         $expiration = $keyValue->getExpirationTimestamp();
     }
     return $expiration;
 }
コード例 #3
0
 /**
  * {@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;
 }
コード例 #4
0
 /**
  * @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();
 }
コード例 #5
0
 private function validateExpiration(KeyValue $keyValue)
 {
     if ($keyValue->isExpired()) {
         throw new ExpiredKeyException($keyValue->getKey(), $keyValue->getNamespace());
     }
 }
コード例 #6
0
ファイル: KeyValueTest.php プロジェクト: wopp/keyvalue-bundle
 /**
  * @test
  * @dataProvider getExpiredKeyValues
  */
 public function keyValueShouldBeExpired(KeyValue $keyValue)
 {
     $this->assertTrue($keyValue->isExpired());
 }