Skip to content

Commit

Permalink
Create assertion to determine if a cookie is not expired (#24119)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
roberto-aguilar authored and taylorotwell committed May 5, 2018
1 parent 1fc6cd5 commit eeeeee4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit eeeeee4

Please sign in to comment.