/**
  * @test
  */
 public function it_does_not_use_a_cached_token_when_forced()
 {
     $token = new Token('abcd1234', new \DateTime('+1 hour'));
     $this->cache->expects($this->any())->method('get')->willReturn(json_encode($token));
     $this->pool->expects($this->once())->method('requestToken')->willReturn($this->token);
     $this->assertSame($this->token, $this->pool->getToken(true));
     $this->assertSame($this->token->getId(), $this->pool->getTokenId());
     $this->assertSame($this->endpointUrl, $this->pool->getEndpointUrl());
 }
 /**
  * @test
  * @expectedException \GuzzleHttp\Exception\ClientException
  */
 public function it_fails_with_failed_reathentication()
 {
     $this->cache->set($this->getTokenKey(), $this->getTokenJson());
     $client = $this->factory->createClient($this->tenant);
     Server::enqueue([new Response(403), new Response(401)]);
     try {
         $client->request('get', '/foo');
     } catch (ClientException $e) {
         // original request should not have repeated
         $this->assertCount(2, Server::received());
         throw $e;
     }
 }
 public function testList()
 {
     // list calls are not cached
     $this->innerCache->expects($this->exactly(2))->method('addToList');
     $this->cache->addToList('foo', 'bar');
     $this->cache->addToList('foo', 'bar');
     $this->innerCache->expects($this->exactly(2))->method('getList');
     $this->cache->getList('foo');
     $this->cache->getList('foo');
     $this->innerCache->expects($this->exactly(2))->method('removeFromList');
     $this->cache->removeFromList('foo', 'bar');
     $this->cache->removeFromList('foo', 'bar');
 }
 /**
  * Returns a token to use for the keystone service. Uses cached instance
  * whenever possible.
  *
  * @param bool $forceNew Whether to force creating a new token
  *
  * @return Token
  */
 public function getToken($forceNew = false)
 {
     $tokenName = $this->getCacheKey();
     // see if token is in cache
     if (!$forceNew && ($cachedToken = $this->cache->get($tokenName))) {
         $this->logger->debug('Obtained token from cache');
         $token = $this->createToken($cachedToken);
     }
     if (!isset($token) || !$token instanceof Token || $token->isExpired()) {
         // cache the token and set it to expire 5 seconds before the
         // expiration date, to avoid any concurrence errors.
         $token = $this->requestToken();
         $this->cache->set($tokenName, json_encode($token), $token->getExpirationDate()->getTimestamp() - time() - 5);
     }
     // cache token properties
     $this->endpointUrl = $this->getEndpointUrlFromToken($token);
     $this->tokenId = $token->getId();
     return $token;
 }
 /**
  * {@inheritdoc}
  */
 public function destroy($sessionId)
 {
     return $this->cache->remove($this->prefix . $sessionId);
 }
 /**
  * Clears both the meta cache and Doctrine's entity cache.
  */
 public function clear()
 {
     $this->cache->clear();
     $this->getOrmCache()->flushAll();
 }
Exemple #7
0
 /**
  * @inheritdoc
  */
 public function save($id, $data, $lifeTime = false, array $options = null)
 {
     return $this->cache->set($id, $data, $lifeTime);
 }
Exemple #8
0
 /**
  * @inheritdoc
  */
 protected function doFlush()
 {
     return $this->cache->clear();
 }
Exemple #9
0
 /**
  * @inheritdoc
  */
 public function removeFromList($list, $value)
 {
     // no memory cache for lists
     return $this->cache->removeFromList($list, $value);
 }