Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
N/A
-
Resolution: Fixed
-
Affects Version/s: 1.9.2
-
Fix Version/s: 1.9.5
-
Component/s: Zend_Test_PHPUnit
-
Labels:None
Description
I would like to see the "standard" Zend Framework bootstrapping method to be supported in Zend_Test_PHPUnit_ControllerTestCase. It is confusing and not obvious on how to reuse your Zend_Application_Bootstrap when using the ControllerTestCase.
There are 2 ways that this can be done.
------ First Method ------
Document with code examples on how to use Zend_Application_Bootstrap_* in the Zend_Test_PHPUnit_ControllerTestCase manual. However one issue is that it feels a bit weird as you have to overwrite $this->_frontController manually yourself.
— One Current Example —
public function setUp() { $this->bootstrap = array($this, 'appBootstrap'); parent::setUp(); } public function appBootstrap() { $this->frontController ->registerPlugin(new Bugapp_Plugin_Initialize('development')); }
— Using Zend_Application_Bootstrap Example —
public function setUp() { $this->bootstrap = array($this, 'appBootstrap'); parent::setUp(); } public function appBootstrap() { // Create application, bootstrap, but don't RUN! $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $bootstrap = $application->getBootstrap(); $bootstrap->bootstrap(); //note run() is not called! //front controller now bootstrapped using whatever method you used (config, resource plugin...etc) //Having $this->frontController and $this->_frontController may be hard to explain $this->_frontController = $bootstrap->getResource('frontController'); }
As you can see this is quite simple, but as I noted in the comment it may be confusing to explain that you have to overwrite $this->_frontController not $this->frontController.
------ Second Method ------
Actually supporting Zend_Application_Bootstrap in ControllerTestCase.
public function setUp() { $this->bootstrap = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); parent::setUp(); }
if $this->bootstrap is set to an instance of Zend_Application then have the ControllerTestCase automatically call $bootstrap->bootstrap() for you. Future calls to $this->getFrontController() will retrieve the frontController from the bootstrap instead.
This is a simplified example obviously and I may have missed some details, but it seems obvious for some kind of support of the "standard" bootstrapping method. Bootstrapping can be very lengthy/complex and since the main goal is re-usability why would we want to have a completely different bootstrap method (or duplicated) for controller testing. I think this improvement will "sync" Zend_Test_PHPUnit_ControllerTestCase with the encouraged bootstrap method. This also puts to great use the separate production , development, testing ini settings document in the Zend_Application quick start. It becomes even more important with all the plugins with preDispatch details...etc. I think you get the point
.
Thoughts, suggestions, hate messages are welcomed ![]()
Fixed code format