Skip to content

Commit

Permalink
Add tests for new Last-Modified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
codeguy committed Mar 31, 2015
1 parent b86b7d1 commit d1df3c1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ public function testLastModifiedWithCacheHit()
$this->assertEquals(304, $res->getStatusCode());
}

public function testLastModifiedWithCacheHitAndNewerDate()
{
$now = time();
$lastModified = gmdate('D, d M Y H:i:s T', $now + 86400);
$ifModifiedSince = gmdate('D, d M Y H:i:s T', $now + 172800); // <-- Newer date
$cache = new Cache('public', 86400);
$req = $this->requestFactory()->withHeader('If-Modified-Since', $ifModifiedSince);
$res = new Response();
$next = function (Request $req, Response $res) use ($lastModified) {
return $res->withHeader('Last-Modified', $lastModified);
};
$res = $cache($req, $res, $next);

$this->assertEquals(304, $res->getStatusCode());
}

public function testLastModifiedWithCacheHitAndOlderDate()
{
$now = time();
$lastModified = gmdate('D, d M Y H:i:s T', $now + 86400);
$ifModifiedSince = gmdate('D, d M Y H:i:s T', $now); // <-- Older date
$cache = new Cache('public', 86400);
$req = $this->requestFactory()->withHeader('If-Modified-Since', $ifModifiedSince);
$res = new Response();
$next = function (Request $req, Response $res) use ($lastModified) {
return $res->withHeader('Last-Modified', $lastModified);
};
$res = $cache($req, $res, $next);

$this->assertEquals(200, $res->getStatusCode());
}

public function testLastModifiedWithCacheMiss()
{
$now = time();
Expand Down

0 comments on commit d1df3c1

Please sign in to comment.