Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
fix remaining cookie lifetime test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pine3ree committed Feb 28, 2019
1 parent 42d964b commit 5ebdb3c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions test/PhpSessionPersistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ public function testCookiesSetWithDefaultLifetime()
public function testCookiesSetWithCustomLifetime()
{
$lifetime = 300;
$expectedTimestamp = time() + $lifetime;

$ini = $this->applyCustomSessionOptions([
'cookie_lifetime' => $lifetime,
Expand All @@ -513,11 +512,17 @@ public function testCookiesSetWithCustomLifetime()

$session->set('foo', 'bar');

$expiresMin = time() + $lifetime;
$response = $persistence->persistSession($session, new Response());
$expiresMax = time() + $lifetime;

$setCookie = FigResponseCookies::get($response, session_name());
$this->assertInstanceOf(SetCookie::class, $setCookie);
$this->assertSame($expectedTimestamp, $setCookie->getExpires());

$expires = $setCookie->getExpires();

$this->assertGreaterThanOrEqual($expiresMin, $expires);
$this->assertLessThanOrEqual($expiresMax, $expires);

$this->restoreOriginalSessionIniSettings($ini);
}
Expand All @@ -533,11 +538,17 @@ public function testAllowsSessionToSpecifyLifetime()
$lifetime = 300;
$session->persistSessionFor($lifetime);

$expiresMin = time() + $lifetime;
$response = $persistence->persistSession($session, new Response());
$expiresMax = time() + $lifetime;

$setCookie = FigResponseCookies::get($response, session_name());
$this->assertInstanceOf(SetCookie::class, $setCookie);
$this->assertSame(time() + $lifetime, $setCookie->getExpires());

$expires = $setCookie->getExpires();

$this->assertGreaterThanOrEqual($expiresMin, $expires);
$this->assertLessThanOrEqual($expiresMax, $expires);

// reset lifetime
session_set_cookie_params($originalLifetime);
Expand Down

0 comments on commit 5ebdb3c

Please sign in to comment.