diff --git a/src/Dflydev/FigCookies/SetCookie.php b/src/Dflydev/FigCookies/SetCookie.php index 8b5ccb0..3467673 100644 --- a/src/Dflydev/FigCookies/SetCookie.php +++ b/src/Dflydev/FigCookies/SetCookie.php @@ -28,8 +28,8 @@ class SetCookie private $value; /** @var int */ private $expires = 0; - /** @var int */ - private $maxAge = 0; + /** @var int|null */ + private $maxAge = null; /** @var string|null */ private $path; /** @var string|null */ @@ -62,7 +62,7 @@ public function getExpires() : int return $this->expires; } - public function getMaxAge() : int + public function getMaxAge() : ?int { return $this->maxAge; } @@ -151,7 +151,7 @@ public function withMaxAge(?int $maxAge = null) : self { $clone = clone($this); - $clone->maxAge = (int) $maxAge; + $clone->maxAge = $maxAge; return $clone; } @@ -349,7 +349,7 @@ private function appendFormattedExpiresPartIfSet(array $cookieStringParts) : arr */ private function appendFormattedMaxAgePartIfSet(array $cookieStringParts) : array { - if ($this->maxAge) { + if (is_int($this->maxAge)) { $cookieStringParts[] = sprintf('Max-Age=%s', $this->maxAge); } diff --git a/tests/Dflydev/FigCookies/SetCookieTest.php b/tests/Dflydev/FigCookies/SetCookieTest.php index 946fd6d..821aeba 100644 --- a/tests/Dflydev/FigCookies/SetCookieTest.php +++ b/tests/Dflydev/FigCookies/SetCookieTest.php @@ -140,6 +140,20 @@ public function provideParsesFromSetCookieStringData() : array ->withHttpOnly(true) ->withSameSite(SameSite::lax()), ], + [ + 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Path=/; Max-Age=0', + SetCookie::create('lu') + ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg') + ->withMaxAge(0) + ->withPath('/'), + ], + [ + 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Path=/', + SetCookie::create('lu') + ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg') + ->withMaxAge(null) + ->withPath('/'), + ], ]; }