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()); }
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()); }