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

Commit

Permalink
Merge 31121a6 into 0aac376
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 26, 2019
2 parents 0aac376 + 31121a6 commit d0d0d0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/PhpSessionPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use function gmdate;
use function ini_get;
use function random_bytes;
use function session_destroy;
use function session_id;
use function session_name;
use function session_start;
Expand Down Expand Up @@ -190,6 +191,10 @@ private function startSession(string $id, array $options = []) : void
*/
private function regenerateSession() : string
{
if (PHP_SESSION_ACTIVE === session_status()) {
session_destroy();
}

session_write_close();
$id = $this->generateSessionId();
$this->startSession($id, [
Expand Down
17 changes: 17 additions & 0 deletions test/PhpSessionPersistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,23 @@ public function testInitializeIdRegeneratesSessionId()
$this->assertFalse($actual->isRegenerated());
}

public function testRegenerateWhenSessionAlreadyActiveDestroyExistingSessionFirst()
{
session_start();

$_SESSION['test'] = 'value';
$fileSession = realpath(session_save_path() . '/sess_' . session_id());

$this->assertTrue(file_exists($fileSession));

$persistence = new PhpSessionPersistence();
$session = new Session(['foo' => 'bar']);
$session = $session->regenerate();
$persistence->persistSession($session, new Response());

$this->assertFalse(file_exists($fileSession));
}

public function testInitializeIdReturnsSessionUnaltered()
{
$persistence = new PhpSessionPersistence();
Expand Down

0 comments on commit d0d0d0a

Please sign in to comment.