public function testCacheHits()
 {
     $request = $this->createMockRequest();
     $response = $this->createMockResponse();
     $cacheKey1 = $cacheKey2 = null;
     $cache = $this->createMockCache();
     // the cache contains a response for the current request
     $cache->expects($this->once())->method('contains')->will($this->returnCallback(function ($id) use(&$cacheKey1) {
         $cacheKey1 = $id;
         return true;
     }));
     $client = $this->createMockClient();
     // the client should not be called
     $client->expects($this->never())->method('send');
     $cachedResponse = new \Buzz\Message\Response();
     $cachedHeaders = array('CachedHeader');
     $cachedContent = 'Cached response';
     $cachedResponse->setHeaders($cachedHeaders);
     $cachedResponse->setContent($cachedContent);
     // the serialized response will be retrieved from the cache
     $cache->expects($this->once())->method('fetch')->will($this->returnCallback(function ($id) use(&$cacheKey2, $cachedResponse) {
         $cacheKey2 = $id;
         return serialize($cachedResponse);
     }));
     $response->expects($this->once())->method('setHeaders')->with($cachedHeaders);
     $response->expects($this->once())->method('setContent')->with($cachedContent);
     $cachedClient = new CachedClient($client, $cache);
     $cachedClient->send($request, $response);
     $this->assertSame(0, $cachedClient->getMisses());
     $this->assertSame(1, $cachedClient->getHits());
     $this->assertSame($cacheKey1, $cacheKey2);
 }
 private function loadMockResponse($parameters)
 {
     $parametersArray = array();
     parse_str($parameters, $parametersArray);
     $simulatedResponse = MockEobotResponder::getResponse($parametersArray);
     $response = new \Buzz\Message\Response();
     list($headers, $content) = $this->parseResponse($simulatedResponse);
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }
 public function testFetch()
 {
     $response = new \Buzz\Message\Response();
     $response->setContent(file_get_contents(__DIR__ . '/Fixtures/Torrenthound.xml'));
     $response->setHeaders(array('HTTP/1.1 200 OK'));
     $browser = $this->getMock('Buzz\\Browser');
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $showCollection = new ShowCollection();
     $provider = new TorrenthoundTorrentProvider($browser);
     $provider->setShowCollection($showCollection);
     $provider->fetch();
     $this->assertCount(6, $showCollection->getShows());
 }