public function testCachesDescriptions()
 {
     $adapter = new DoctrineCacheAdapter(new ArrayCache());
     $factory = new ServiceDescriptionFactory();
     // Create a service and add it to the cache
     $service = $factory->build($this->jsonFile, array('cache.adapter' => $adapter));
     // Ensure the cache key was set
     $this->assertTrue($adapter->contains('d' . crc32($this->jsonFile)));
     // Grab the service from the cache
     $this->assertEquals($service, $factory->build($this->jsonFile, array('cache.adapter' => $adapter)));
 }
Exemplo n.º 2
0
 public function testCachesArtifacts()
 {
     $jsonFile = __DIR__ . '/../TestData/test_service.json';
     $adapter = new DoctrineCacheAdapter(new ArrayCache());
     $factory = $this->getFactory();
     $factory->expects($this->once())->method('getClassName')->will($this->returnValue('Guzzle\\Service\\Builder\\JsonServiceBuilderFactory'));
     // Create a service and add it to the cache
     $service = $factory->build($jsonFile, array('cache.adapter' => $adapter));
     // Ensure the cache key was set
     $this->assertTrue($adapter->contains('guzzle' . crc32($jsonFile)));
     // Grab the service from the cache
     $this->assertEquals($service, $factory->build($jsonFile, array('cache.adapter' => $adapter)));
 }
Exemplo n.º 3
0
 /**
  * @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));
 }
Exemplo n.º 4
0
 public function testDescriptionIsCacheable()
 {
     $jsonFile = __DIR__ . '/../../TestData/test_service.json';
     $adapter = new DoctrineCacheAdapter(new ArrayCache());
     $builder = ServiceBuilder::factory($jsonFile, array('cache.adapter' => $adapter));
     // Ensure the cache key was set
     $this->assertTrue($adapter->contains('guzzle' . crc32($jsonFile)));
     // Grab the service from the cache
     $this->assertEquals($builder, ServiceBuilder::factory($jsonFile, array('cache.adapter' => $adapter)));
 }
 /**
  * @covers \Guzzle\Common\Cache\DoctrineCacheAdapter::delete
  */
 public function testDelete()
 {
     $this->assertTrue($this->adapter->save('test', 'data', 1000));
     $this->assertTrue($this->adapter->delete('test'));
     $this->assertFalse($this->adapter->contains('test'));
 }