-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Phalcon\Session\Bag: add of initialization for remove()
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,4 +83,45 @@ function () { | |
} | ||
); | ||
} | ||
|
||
/** | ||
* Delete a value in a bag (not initialized internally) | ||
* | ||
* @author Fabio Mora <[email protected]> | ||
* @since 2017-02-21 | ||
*/ | ||
public function testDeleteInitializeInternalData() | ||
{ | ||
$this->specify( | ||
"Delete a value in a non initialized bag has failed", | ||
function () { | ||
$reflectionClass = new \ReflectionClass(\Phalcon\Session\Bag::class); | ||
$_data = $reflectionClass->getProperty('_data'); | ||
$_data->setAccessible(true); | ||
$_initialized = $reflectionClass->getProperty('_initialized'); | ||
$_initialized->setAccessible(true); | ||
|
||
// Setup a bag with a value | ||
$bag = new \Phalcon\Session\Bag('fruit'); | ||
$bag->set('apples', 10); | ||
expect($bag->get('apples'))->same(10); | ||
expect($_data->getValue($bag))->same(['apples' => 10]); | ||
expect($_initialized->getValue($bag))->true(); | ||
|
||
// Emulate a reset of the internal status (e.g. as would be done by a sleep/wakeup handler) | ||
$serializedBag = serialize($bag); | ||
unset($bag); | ||
|
||
$bag = unserialize($serializedBag); | ||
$_data->setValue($bag, NULL); | ||
$_initialized->setValue($bag, false); | ||
|
||
// Delete | ||
expect($_initialized->getValue($bag))->false(); | ||
expect($bag->remove('apples'))->true(); | ||
expect($bag->get('apples'))->null(); | ||
expect($_initialized->getValue($bag))->true(); | ||
} | ||
); | ||
} | ||
} |