Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Create assertion to determine if a cookie is expired #21793

Merged
merged 1 commit into from
Oct 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Carbon;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Traits\Macroable;
use PHPUnit\Framework\Assert as PHPUnit;
Expand Down Expand Up @@ -170,6 +171,29 @@ public function assertCookie($cookieName, $value = null, $encrypted = true)
return $this;
}

/**
* Asserts that the response contains the given cookie and is expired.
*
* @param string $cookieName
* @return $this
*/
public function assertCookieExpired($cookieName)
{
PHPUnit::assertNotNull(
$cookie = $this->getCookie($cookieName),
"Cookie [{$cookieName}] not present on response."
);

$expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime());

PHPUnit::assertTrue(
$expiresAt->lessThan(Carbon::now()),
"Cookie [{$cookieName}] is not expired, it expires at [{$expiresAt}]."
);

return $this;
}

/**
* Get the given cookie from the response.
*
Expand Down