Skip to content

Commit d1df3c1

Browse files
committed
Add tests for new Last-Modified logic
1 parent b86b7d1 commit d1df3c1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/CacheTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,38 @@ public function testLastModifiedWithCacheHit()
6464
$this->assertEquals(304, $res->getStatusCode());
6565
}
6666

67+
public function testLastModifiedWithCacheHitAndNewerDate()
68+
{
69+
$now = time();
70+
$lastModified = gmdate('D, d M Y H:i:s T', $now + 86400);
71+
$ifModifiedSince = gmdate('D, d M Y H:i:s T', $now + 172800); // <-- Newer date
72+
$cache = new Cache('public', 86400);
73+
$req = $this->requestFactory()->withHeader('If-Modified-Since', $ifModifiedSince);
74+
$res = new Response();
75+
$next = function (Request $req, Response $res) use ($lastModified) {
76+
return $res->withHeader('Last-Modified', $lastModified);
77+
};
78+
$res = $cache($req, $res, $next);
79+
80+
$this->assertEquals(304, $res->getStatusCode());
81+
}
82+
83+
public function testLastModifiedWithCacheHitAndOlderDate()
84+
{
85+
$now = time();
86+
$lastModified = gmdate('D, d M Y H:i:s T', $now + 86400);
87+
$ifModifiedSince = gmdate('D, d M Y H:i:s T', $now); // <-- Older date
88+
$cache = new Cache('public', 86400);
89+
$req = $this->requestFactory()->withHeader('If-Modified-Since', $ifModifiedSince);
90+
$res = new Response();
91+
$next = function (Request $req, Response $res) use ($lastModified) {
92+
return $res->withHeader('Last-Modified', $lastModified);
93+
};
94+
$res = $cache($req, $res, $next);
95+
96+
$this->assertEquals(200, $res->getStatusCode());
97+
}
98+
6799
public function testLastModifiedWithCacheMiss()
68100
{
69101
$now = time();

0 commit comments

Comments
 (0)