예제 #1
0
 public function testGetters()
 {
     $cacheKey = 'cacheKey';
     $cacheFor = 100;
     $request = new CachedRequest('url', 'body', $cacheKey, $cacheFor);
     $this->assertEquals($cacheKey, $request->getCacheKey());
     $this->assertEquals($cacheFor, $request->getCacheFor());
 }
예제 #2
0
 /**
  * Method send request for api
  *
  * @param CachedRequest $request
  * @return string
  */
 public function sendCached(CachedRequest $request)
 {
     $cached = $this->memcache->get($request->getCacheKey());
     if (false !== $cached) {
         return $cached;
     }
     $response = $this->send($request);
     $this->memcache->set($request->getCacheKey(), (string) $response->getBody(), 0, $request->getCacheFor());
     return $response->getBody();
 }
예제 #3
0
 public function testSendCachedWithCacheReturnsCache()
 {
     $cacheKey = 'CACHE_KEY';
     $body = 'BODY';
     $this->cachedRequestMock->expects($this->any())->method('getCacheKey')->willReturn($cacheKey);
     $this->cachedRequestMock->expects($this->never())->method('getCacheFor');
     $this->guzzleClientMock->expects($this->never())->method('send');
     $this->memcacheMock->expects($this->once())->method('get')->with($cacheKey)->willReturn($body);
     $this->memcacheMock->expects($this->never())->method('set');
     $client = new ClientCached($this->guzzleClientMock, $this->memcacheMock);
     $this->assertSame($body, $client->sendCached($this->cachedRequestMock));
 }