Exemplo n.º 1
0
 public function testDeprecatedFunctions()
 {
     $cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->getMockForAbstractClass();
     $instance = new CachedCurlRequest(curl_init(), $cache);
     $instance->setExpiryInSeconds(42);
     $instance->setCachePrefix('Foo');
     $this->assertEquals(42, $instance->getOption(ONOI_HTTP_REQUEST_RESPONSECACHE_TTL));
     $this->assertEquals('Foo', $instance->getOption(ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX));
 }
 public function testSaveResponse()
 {
     $cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->setMethods(array('save', 'contains'))->getMockForAbstractClass();
     $cache->expects($this->once())->method('save')->with($this->equalTo('onoi:http:823a603f972819c10d13f32b14460573'), $this->anything(), $this->equalTo(42));
     $instance = new CachedCurlRequest(curl_init(), $cache);
     $instance->setExpiryInSeconds(42);
     $instance->setOption(CURLOPT_URL, 'http://example.org');
     $instance->setOption(CURLOPT_RETURNTRANSFER, true);
     $instance->execute();
 }
 public function testCachedRequestToExternalUrl()
 {
     $target = 'http://example.org/';
     $cache = new FixedInMemoryLruCache();
     $instance = new CachedCurlRequest(curl_init($target), $cache);
     if (!$instance->ping()) {
         $this->markTestSkipped("Can't connect to " . $target);
     }
     $instance->setExpiryInSeconds(42);
     $instance->setOption(CURLOPT_RETURNTRANSFER, true);
     $this->assertInternalType('string', $instance->execute());
     $this->assertFalse($instance->isCached());
     // Repeated request
     $instance->setOption(CURLOPT_RETURNTRANSFER, true);
     $instance->execute();
     $this->assertTrue($instance->isCached());
 }
Exemplo n.º 4
0
 public function testCachedRequestToExternalUrl()
 {
     $target = 'http://example.org/';
     $cache = new FixedInMemoryLruCache();
     $instance = new CachedCurlRequest(curl_init($target), $cache);
     if (!$instance->ping()) {
         $this->markTestSkipped("Can't connect to " . $target);
     }
     $instance->setOption(CURLOPT_RETURNTRANSFER, true);
     $instance->setOption(ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42);
     $instance->setOption(ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX, 'foo');
     $this->assertInternalType('string', $instance->execute());
     $this->assertFalse($instance->isFromCache());
     // Repeated request
     $instance->setOption(CURLOPT_RETURNTRANSFER, true);
     $instance->setOption(ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42);
     $instance->setOption(ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX, 'foo');
     $instance->execute();
     $this->assertTrue($instance->isFromCache());
 }