/** * @covers Guzzle\Http\Plugin\CachePlugin::onRequestSent * @covers Guzzle\Http\Plugin\CachePlugin::onRequestBeforeSend * @covers Guzzle\Http\Plugin\CachePlugin::saveCache */ public function testSkipsNonReadableResponseBodies() { // Send a 200 OK script to the testing server $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata"); // Create a new Cache plugin $plugin = new CachePlugin($this->adapter); $client = new Client($this->getServer()->getUrl()); $client->getEventDispatcher()->addSubscriber($plugin); // Create a new request using the Cache plugin $request = $client->get(); // Create a temp file that is not readable $tempFile = tempnam('/tmp', 'temp_stream_data'); // Set the non-readable stream as the response body so that it can't be cached $request->setResponseBody(EntityBody::factory(fopen($tempFile, 'w'))); $request->send(); // Calculate the cache key like the cache plugin does $key = $plugin->getCacheKey($request); // Make sure that the cache plugin set the request in cache $this->assertFalse($this->adapter->fetch($key)); }
/** * @covers \Guzzle\Common\Cache\DoctrineCacheAdapter::fetch */ public function testFetch() { $this->assertTrue($this->adapter->save('test', 'data', 1000)); $this->assertEquals('data', $this->adapter->fetch('test')); }