diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index c2b1596a8ea8..97f6ea4d98a3 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -242,6 +242,29 @@ public function assertCookieExpired($cookieName) return $this; } + /** + * Asserts that the response contains the given cookie and is not expired. + * + * @param string $cookieName + * @return $this + */ + public function assertCookieNotExpired($cookieName) + { + PHPUnit::assertNotNull( + $cookie = $this->getCookie($cookieName), + "Cookie [{$cookieName}] not present on response." + ); + + $expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime()); + + PHPUnit::assertTrue( + $expiresAt->greaterThan(Carbon::now()), + "Cookie [{$cookieName}] is expired, it expired at [{$expiresAt}]." + ); + + return $this; + } + /** * Asserts that the response does not contains the given cookie. *