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); }
public function testGetShipping() { $response = new \Buzz\Message\Response(); $response->setContent(file_get_contents('./tests/fixtures/product/shipping.json')); $buzz = $this->getMock('Buzz\\Browser'); $buzz->expects($this->once())->method('get')->willReturn($response); $c = new \Catalol\Client($buzz, 'domain.com', '123'); $this->assertInstanceOf('Catalol\\ShippingCostSummary', $c->getShipping(new \Catalol\Shipping())); }
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()); }
protected function getResultNotFound() { $response = new \Buzz\Message\Response(); $response->addHeader('HTTP/1.1 404 Not Found'); return $response; }
private function getResultEmails($additionalEmails = array()) { $emails = array('*****@*****.**', '*****@*****.**'); $response = new \Buzz\Message\Response(); $response->setContent(array_merge($emails, $additionalEmails)); $response->addHeader('HTTP/1.1 200 OK'); return $response; }
private function getResultGist($details = array()) { $gists = $this->getGists(); $response = new \Buzz\Message\Response(); $response->setContent(array_merge($gists[0], $details)); $response->addHeader('HTTP/1.1 200 OK'); return $response; }
private function getResultFollowing() { $data = array(array('login' => 'octocat', 'id' => 1, 'gravatar_url' => 'https://github.com/images/error/octocat_happy.gif', 'url' => 'https://api.github.com/users/octocat')); $response = new \Buzz\Message\Response(); $response->setContent($data); $response->addHeader('HTTP/1.1 200 OK'); return $response; }
private function getResultKey($details = array()) { $key = array('url' => 'https://api.github.com/user/keys/1', 'id' => 1, 'title' => 'octocat@octomac', 'key' => 'ssh-rsa AAA...'); $response = new \Buzz\Message\Response(); $response->setContent(array_merge($key, $details)); $response->addHeader('HTTP/1.1 200 OK'); return $response; }