Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
Added an integration test for the calculation of the "resident_time"
Browse files Browse the repository at this point in the history
  • Loading branch information
bmancone committed Aug 5, 2015
1 parent 77246ff commit 713ffb3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/IntegrationTest.php
Expand Up @@ -557,6 +557,48 @@ public function test410CacheDelete()
$this->fourXXCacheDelete(410);
}

/**
* Test the resident_time calculation (RFC7234 4.2.3)
*/
public function testAgeIsIncremented()
{
Server::enqueue([
new Response(200, [
'Date' => $this->date(),
'Cache-Control' => 'public, max-age=60',
'Age' => '59'
], Stream::factory('Age is 59!')),
new Response(200, [
'Date' => $this->date(),
'Cache-Control' => 'public, max-age=60',
'Age' => '0'
], Stream::factory('It works!')),
]);

$client = $this->setupClient();

// First request : the response is cached
$response1 = $client->get('/foo');
$this->assertEquals(200, $response1->getStatusCode());
$this->assertEquals('MISS from GuzzleCache', $response1->getHeader('X-Cache-Lookup'));
$this->assertEquals('Age is 59!', $this->getResponseBody($response1));

// Second request : cache hit, age is now 60
sleep(1);
$response2 = $client->get('/foo');
$this->assertEquals(200, $response1->getStatusCode());
$this->assertEquals('HIT from GuzzleCache', $response2->getHeader('X-Cache-Lookup'));

// This request should not be valid anymore : age is 59 + 2 = 61 which is strictly greater than 60
sleep(1);
$response3 = $client->get('/foo');
$this->assertEquals(200, $response3->getStatusCode());
$this->assertEquals('MISS from GuzzleCache', $response3->getHeader('X-Cache-Lookup'));
$this->assertEquals('It works!', $this->getResponseBody($response3));

$this->assertCount(2, Server::received());
}

/**
* Decode a response body from TestServer.
*
Expand Down

0 comments on commit 713ffb3

Please sign in to comment.