示例#1
0
 public function testCacheIsSet()
 {
     $httpClient = new GuzzleClient();
     $mock = new Mock([new Response(200, [], new Stream(fopen('data://text/plain,' . '{"toto":"titi"}', 'r')))]);
     $httpClient->getEmitter()->attach($mock);
     // save method should be call once
     $cacheDriver = $this->getMockBuilder('Doctrine\\Common\\Cache\\Cache')->getMock();
     $cacheDriver->expects($this->any())->method('save');
     $cacheDriver->expects($this->any())->method('fetch');
     $options = $this->getClientOptions();
     $options['cache_driver'] = $cacheDriver;
     $tokenStorage = new InMemoryStorage();
     $tokenStorage->setAccessToken(['access_token' => 'DxhqhXaXIRLad', 'expires_in' => 30, 'created_at' => time()]);
     $client = new Client($options, $httpClient, $tokenStorage);
     $client->getAdverts();
 }
 public function testTokenIsExpired()
 {
     $storage = new InMemoryStorage();
     $missingTimePropertyToken = ['access_token' => 'K0TMAJKqZg6'];
     $storage->setAccessToken($missingTimePropertyToken);
     $this->assertTrue($storage->isAccessTokenExpired());
     $validToken = ['access_token' => 'K0TMAJKqZg6', 'created_at' => time(), 'expires_in' => 30];
     $storage->setAccessToken($validToken);
     $this->assertFalse($storage->isAccessTokenExpired());
     $invalidToken = $validToken = ['access_token' => 'K0TMAJKqZg6', 'created_at' => time() - 35, 'expires_in' => 30];
     $storage->setAccessToken($invalidToken);
     $this->assertTrue($storage->isAccessTokenExpired());
 }