ZF-3145: Zend_Controller_Front::resetInstance() doesn't reset helpers which are stored in static variable.


I have find this bug when writing unit tests. After resetting front controller, redirector helper still existed, with all redirection params set earlier. I had to manually reset redirector before every test.

In my opinion when resetting FrontControllers all helpers should be cleared too\ - this would help much in unit testing of controllers.


Zend_Controller_Action_HelperBroker::resetHelpers() should be called, yes

Please evaluate and categorize as necessary.

It's a larger and more complicated issue...

I have meet many issues concerning unit testing and static variables in plugins/helpers/etc that will perstist after executing Zend_Controller_Front::resetInstance() or Zend_Controller_Action_HelperBroker::resetHelpers(); which can in some situations return outdated data or behave in unexpectable way.

For example (unit testing):

My application is using Zend_Layout.

// test #1 starts here

When Zend_Layout::startMvc(array()) is called for the first time it will : - create sigleton instance - register Zend_Layout_Controller_Plugin_Layout in front controller - register helper Zend_Layout_Controller_Action_Helper_Layout

So far everything wotks brilliant....

Lets say I start next test from PHPUnit test suite, bu t before I do it I call $front->resetInstance() and Zend_Controller_Action_HelperBroker::resetHelpers(); to reset environment. After this I will launch code which will set up front controller from scratch, just like was done when application was started. Zend_Layout::startMvc(array()) will be launched again, but Zend_Layout will notice that its singleton was already instantiated, so it won't register Zend_Layout_Controller_Plugin_Layout in front controller anymore.

// test #2 starts here

When secont unittest will be starter, there will be no Zend_Layout_Controller_Plugin_Layout plugin registered in front controller - it's not what we would expect.

There are similar issues with other plugins and helpers, I wonder wheter to file similar bugs or on generic called "Unit testing, ZF - unable to reset environment completely".

What's your feelings about this issue?

PS. Running unit tests as separate processes would resolve my problems but so far it's not possible with PHPUnit (this functionality is in unstable branch).

Scheduling for next minor release.

I've added a call to the helper broker's resetHelpers() method within Z_C_F's resetInstance(). Additionally, we now have the Zend_Test_PHPUnit_ControllerTestCase, which provides infrastructure for testing and solves most (if not all) issues reported.

Changes are current as of r10111.

Updating for the 1.6.0 release.