/**
  * @inheritdoc
  */
 protected function setUp()
 {
     $url = 'http://example.org';
     $user = '******';
     $pass = '******';
     $serviceType = 'object-store';
     $serviceName = 'cdn';
     $this->tenant = new Tenant($url, $user, $pass, $serviceType, $serviceName);
     $this->token = new Token(uniqid(), new \DateTime('+1 hour'));
     $this->token->addServiceCatalog($serviceType, $serviceName, [['publicUrl' => 'http://example.org/v1']]);
 }
 /**
  * @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());
 }
 /**
  * @param Token $token
  *
  * @throws TokenException
  *
  * @return string
  */
 private function getEndpointUrlFromToken(Token $token)
 {
     $catalog = $token->getServiceCatalog($this->tenant->getServiceType(), $this->tenant->getServiceName());
     // use the first endpoint that has was requested
     $endpointType = $this->tenant->getServiceEndpoint() . 'url';
     foreach ($catalog as $endpoint) {
         $endpoint = array_change_key_case($endpoint, CASE_LOWER);
         if (array_key_exists($endpointType, $endpoint)) {
             return $endpoint[$endpointType];
         }
     }
     throw new TokenException('No endpoint with a ' . $this->tenant->getServiceEndpoint() . ' url found');
 }
 /**
  * @test
  * @expectedException \TreeHouse\Keystone\Client\Exception\TokenException
  */
 public function it_throws_exception_on_undefined_service_catalog_name()
 {
     $token = new Token(uniqid(), new \DateTime('+ 1 minute'));
     $token->addServiceCatalog('compute', 'test', [['adminurl' => 'https://admin.example.org', 'publicurl' => 'https://example.org']]);
     $token->getServiceCatalog('compute', 'api');
 }