Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phalcon\Session\Bag: add of initialization for remove() #12647

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixes internal cache saving in `Phalcon\Mvc\Model\Binder` when no cache backend is used
- Added the ability to get original values from `Phalcon\Mvc\Model\Binder`, added `Phalcon\Mvc\Micro::getModelBinder`, `Phalcon\Dispatcher::getModelBinder`
- Added `prepend` parameter to `Phalcon\Loader::register` to specify autoloader's loading order to top most
- Fixed `Phalcon\Session\Bag::remove` to initialize the bag before removing a value

# [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (XXXX-XX-XX)
- Fixed Isnull check is not correct when the model field defaults to an empty string. [#12507](https://github.com/phalcon/cphalcon/issues/12507)
Expand Down
4 changes: 4 additions & 0 deletions phalcon/session/bag.zep
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,
*/
public function remove(string! property) -> boolean
{
if this->_initialized === false {
this->initialize();
}

var data;

let data = this->_data;
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/Session/BagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
);
}
}