ZF-8115: FlashMessenger doesn't work in testing

Issue Type: Improvement Created: 2009-10-21T11:04:16.000+0000 Last Updated: 2012-03-16T12:09:57.000+0000 Status: Open Fix version(s): Reporter: SP (kaioptera) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

  • zf-caretaker-adamlundrigan

Related issues: Attachments:


The FlashMessenger action helper is not test-friendly - if a controller test dispatches an action that adds a message, then resets the MVC system as it must, then dispatches an action that should show the message, the message won't be in the response as one would expect.

This is because:

  1. In Zend_Test_PHPUnit_ControllerTestCase::reset(), the session superglobal is always blown away ($_SESSION = array()), eliminating any messages that have been set. I think there should at least be an option to not do this, to support testing multiple requests pertaining to the same session, and dependent on session data. (I worked around it by just stashing the current value of $_SESSION before calling $this->bootstrap() in my test class and restoring it immediately after to simulate a persisted session.)
  2. Even though resetting the MVC system gets rid of the initial FlashMessenger instance and a new one is later created, the class stores its Zend_Session_Namespace object in a static protected variable and uses the existence of this variable as a flag to decide if it needs to retrieve messages from the session, killing the ability to use FlashMessenger in testing.


Posted by Adam Lundrigan (adamlundrigan) on 2012-03-16T12:09:57.000+0000

Mocking is a much better approach to this type of unit testing. See [~bittarman]'s blog post for an example of how to do that:…

With his permission I will adapt the blog post into a manual page section.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.