/**
  * @param RequestInterface $request
  * @param bool             $forceNew
  *
  * @return RequestInterface
  */
 public function signRequest(RequestInterface $request, $forceNew = false)
 {
     try {
         // force-get a new token if it was requested, if not, the regular
         // caching mechanism will be used so the call is not necessary here.
         if (true === $forceNew) {
             $this->pool->getToken($forceNew);
         }
         // create a new request with the new uri and the token added to the headers
         $uri = Uri::resolve(new Uri($this->pool->getEndpointUrl()), $request->getUri());
         return $request->withUri($uri)->withHeader('X-Auth-Token', $this->pool->getTokenId());
     } catch (TokenException $e) {
         throw new ClientException('Could not obtain token', $request, null, $e);
     }
 }
 /**
  * @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());
 }