diff --git a/CHANGELOG.md b/CHANGELOG.md index f30bea1eb8d..dfd0bb0e1ca 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/phalcon/flash/session.zep b/phalcon/flash/session.zep index 3a7c7797d0a..110f7edc8ec 100644 --- a/phalcon/flash/session.zep +++ b/phalcon/flash/session.zep @@ -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. | @@ -44,14 +44,20 @@ class Session extends FlashBase implements FlashInterface let session = 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; } diff --git a/tests/unit/Flash/SessionTest.php b/tests/unit/Flash/SessionTest.php index 203b1ad4947..af66c4f0f1f 100644 --- a/tests/unit/Flash/SessionTest.php +++ b/tests/unit/Flash/SessionTest.php @@ -136,6 +136,27 @@ function () { ); } + /** + * Tests getMessages in case of non existent type request + * + * @issue 11941 + * @author Serghei Iakovlev + * @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 *