diff --git a/src/Cookie/SetCookie.php b/src/Cookie/SetCookie.php index ac9a89081..6fdee0dd3 100644 --- a/src/Cookie/SetCookie.php +++ b/src/Cookie/SetCookie.php @@ -333,7 +333,7 @@ public function matchesDomain($domain) */ public function isExpired() { - return $this->getExpires() && time() > $this->getExpires(); + return $this->getExpires() !== null && time() > $this->getExpires(); } /** diff --git a/tests/Cookie/SetCookieTest.php b/tests/Cookie/SetCookieTest.php index 3ddd08201..e1229212d 100644 --- a/tests/Cookie/SetCookieTest.php +++ b/tests/Cookie/SetCookieTest.php @@ -361,4 +361,45 @@ public function testParseCookie($cookie, $parsed) } } } + + /** + * Provides the data for testing isExpired + * + * @return array + */ + public function isExpiredProvider() { + return array( + array( + 'FOO=bar; expires=Thu, 01 Jan 1970 00:00:00 GMT;', + true, + ), + array( + 'FOO=bar; expires=Thu, 01 Jan 1970 00:00:01 GMT;', + true, + ), + array( + 'FOO=bar; expires='.date(\DateTime::RFC1123, time()+10).';', + false, + ), + array( + 'FOO=bar; expires='.date(\DateTime::RFC1123, time()-10).';', + true, + ), + array( + 'FOO=bar;', + false, + ), + ); + } + + /** + * @dataProvider isExpiredProvider + */ + public function testIsExpired($cookie, $expired) + { + $this->assertEquals( + $expired, + SetCookie::fromString($cookie)->isExpired() + ); + } }