Conditions | 2 |
Paths | 2 |
Total Lines | 39 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
19 | public function testCachedRequestToExternalUrl() { |
||
20 | |||
21 | $target = 'http://example.org/'; |
||
22 | |||
23 | $cache = new FixedInMemoryLruCache(); |
||
24 | |||
25 | $instance = new CachedCurlRequest( |
||
26 | curl_init( $target ), |
||
27 | $cache |
||
28 | ); |
||
29 | |||
30 | if ( !$instance->ping() ) { |
||
31 | $this->markTestSkipped( "Can't connect to " . $target ); |
||
32 | } |
||
33 | |||
34 | $instance->setOption( CURLOPT_RETURNTRANSFER, true ); |
||
35 | $instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42 ); |
||
36 | $instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX, 'foo' ); |
||
37 | |||
38 | $this->assertInternalType( |
||
39 | 'string', |
||
40 | $instance->execute() |
||
41 | ); |
||
42 | |||
43 | $this->assertFalse( |
||
44 | $instance->isFromCache() |
||
45 | ); |
||
46 | |||
47 | // Repeated request |
||
48 | $instance->setOption( CURLOPT_RETURNTRANSFER, true ); |
||
49 | $instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42 ); |
||
50 | $instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX, 'foo' ); |
||
51 | |||
52 | $instance->execute(); |
||
53 | |||
54 | $this->assertTrue( |
||
55 | $instance->isFromCache() |
||
56 | ); |
||
57 | } |
||
58 | |||
60 |