Skip to content

Commit

Permalink
Fixed Phalcon\Session\Flash::getMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Jul 3, 2016
1 parent b438d9e commit 0b1b955
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
- Fixed matching host name by `Phalcon\Mvc\Route::handle` when using port on current host name [#2573](https://github.com/phalcon/cphalcon/issues/2573)
- Fixed `Phalcon\Text:dynamic()` to allow custom separator [#11215](https://github.com/phalcon/cphalcon/issues/11215)
- Fixed `Phalcon\Validation::appendMessage` to allow append message to the empty stack [#10405](https://github.com/phalcon/cphalcon/issues/10405)
- Fixed `Phalcon\Session\Flash::getMessages`. Now it returns an empty array in case of non existent message type request [#11941](https://github.com/phalcon/cphalcon/issues/11941)

# [2.0.13](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.13) (2016-05-19)
- Restored `Phalcon\Text::camelize` behavior [#11767](https://github.com/phalcon/cphalcon/issues/11767)
Expand Down
10 changes: 8 additions & 2 deletions phalcon/flash/session.zep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
Expand Down Expand Up @@ -44,14 +44,20 @@ class Session extends FlashBase implements FlashInterface
let session = <SessionInterface> dependencyInjector->getShared("session"),
messages = session->get("_flashMessages");

if typeof type == "string" && isset(messages[type]) {
if typeof type == "string" {
if !isset messages[type] {
return [];
}

if !fetch returnMessages, messages[type] {
let returnMessages = [];
}

if remove === true {
unset(messages[type]);
session->set("_flashMessages", messages);
}

return returnMessages;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/unit/Flash/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ function () {
);
}

/**
* Tests getMessages in case of non existent type request
*
* @issue 11941
* @author Serghei Iakovlev <serghei@phalconphp.com>
* @since 2016-07-03
*/
public function testGetNonExistentType()
{
$this->specify(
'The getMessages() method does not return an empty array in case of non existent type request',
function () {
$flash = $this->getFlash();
$flash->error('sample error');

expect($flash->getMessages('success', false))->equals([]);
verify_that(count($flash->getMessages()) === 1);
}
);
}

/**
* Tests clear method
*
Expand Down

0 comments on commit 0b1b955

Please sign in to comment.