From ea114cb763d127bdcf1c8c292cd1313babe9cd44 Mon Sep 17 00:00:00 2001 From: Roberto Aguilar Date: Sat, 5 May 2018 09:02:14 -0500 Subject: [PATCH] Create assertion to determine if a cookie is not expired This new assertion will: - Fail if the cookie is not present at all - Fail if the cookie is present but expired - Pass if the cookie is present and not expired --- .../Foundation/Testing/TestResponse.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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. *