Skip to content

Commit

Permalink
[#14688] - Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Jan 6, 2020
1 parent 0efda8d commit 3d40e8e
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions tests/integration/Session/Manager/ExistsDestroyCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ExistsDestroyCest
public function sessionManagerExistsDestroy(IntegrationTester $I)
{
$I->wantToTest('Session\Manager - exists()/destroy()');
$store = $_SESSION ?? [];
$_SESSION = [];

$manager = new Manager();
$files = $this->getSessionStream();
$manager->setAdapter($files);
Expand All @@ -46,6 +49,8 @@ public function sessionManagerExistsDestroy(IntegrationTester $I)

$actual = $manager->exists();
$I->assertFalse($actual);

$_SESSION = $store;
}

/**
Expand All @@ -60,6 +65,9 @@ public function sessionManagerExistsDestroy(IntegrationTester $I)
public function sessionManagerDestroySuperGlobal(IntegrationTester $I)
{
$I->wantToTest('Session\Manager - destroy() - clean $_SESSION');
$store = $_SESSION ?? [];
$_SESSION = [];

$manager = new Manager();
$files = $this->getSessionStream();
$manager->setAdapter($files);
Expand All @@ -71,13 +79,57 @@ public function sessionManagerDestroySuperGlobal(IntegrationTester $I)
$I->assertTrue($actual);

$manager->set('test1', __METHOD__);
$I->assertArrayHasKey('#test1', $_SESSION);
$I->assertContains(__METHOD__, $_SESSION['#test1']);
$I->assertArrayHasKey('test1', $_SESSION);
$I->assertContains(__METHOD__, $_SESSION['test1']);

$manager->destroy();
$I->assertArrayNotHasKey('#test1', $_SESSION);
$I->assertArrayNotHasKey('test1', $_SESSION);

$actual = $manager->exists();
$I->assertFalse($actual);

$_SESSION = $store;
}

/**
* Tests Phalcon\Session\Manager :: destroy() - clean $_SESSION with uniquid
*
* @author Phalcon Team <[email protected]>
* @since 2020-01-06
*/
public function sessionManagerDestroySuperGlobalUniquid(IntegrationTester $I)
{
$I->wantToTest('Session\Manager - destroy() - clean $_SESSION with uniquid');

$store = $_SESSION ?? [];
$_SESSION = [];

$manager = new Manager();
$files = $this->getSessionStream();
$manager->setAdapter($files);
$manager->setOptions(
[
'uniqueId' => 'aaa'
]
);

$actual = $manager->start();
$I->assertTrue($actual);

$actual = $manager->exists();
$I->assertTrue($actual);

$manager->set('test1', __METHOD__);

$I->assertArrayHasKey('aaa#test1', $_SESSION);
$I->assertContains(__METHOD__, $_SESSION['aaa#test1']);

$manager->destroy();
$I->assertArrayNotHasKey('aaa#test1', $_SESSION);

$actual = $manager->exists();
$I->assertFalse($actual);

$_SESSION = $store;
}
}

0 comments on commit 3d40e8e

Please sign in to comment.