diff --git a/src/Cookie/SetCookie.php b/src/Cookie/SetCookie.php index 7a427df9c..19fc27114 100644 --- a/src/Cookie/SetCookie.php +++ b/src/Cookie/SetCookie.php @@ -358,7 +358,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 e74a987bb..ec5ebb2fc 100644 --- a/tests/Cookie/SetCookieTest.php +++ b/tests/Cookie/SetCookieTest.php @@ -396,4 +396,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() + ); + } }