BUG Fix Director::test() not persisting removed session keys on teardown

This commit is contained in:
Damian Mooyman 2018-02-07 11:03:32 +13:00
parent 62057befdb
commit 2225cf4c95
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A

View File

@ -206,12 +206,17 @@ class Director implements TemplateGlobalProvider
if ($session instanceof Session) { if ($session instanceof Session) {
// Note: If passing $session as object, ensure that changes are written back // Note: If passing $session as object, ensure that changes are written back
// This is important for classes such as FunctionalTest which emulate cross-request persistence // This is important for classes such as FunctionalTest which emulate cross-request persistence
$newVars['_SESSION'] = $session->getAll(); $newVars['_SESSION'] = $sessionArray = $session->getAll();
$finally[] = function () use ($session) { $finally[] = function () use ($session, $sessionArray) {
if (isset($_SESSION)) { if (isset($_SESSION)) {
// Set new / updated keys
foreach ($_SESSION as $key => $value) { foreach ($_SESSION as $key => $value) {
$session->set($key, $value); $session->set($key, $value);
} }
// Unset removed keys
foreach (array_diff_key($sessionArray, $_SESSION) as $key => $value) {
$session->clear($key);
}
} }
}; };
} else { } else {