Zend Framework

Support or document Zend_Application_Bootstrap usage in Zend_Test_PHPUnit_ControllerTestCase

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: N/A 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

Activity

Hide
Duo Zheng added a comment -

Fixed code format

Show
Duo Zheng added a comment - Fixed code format
Hide
Duo Zheng added a comment -

Made adjustment to title

Show
Duo Zheng added a comment - Made adjustment to title
Hide
Duo Zheng added a comment -

Clarifying some confusing writing.

Show
Duo Zheng added a comment - Clarifying some confusing writing.
Hide
Duo Zheng added a comment -

Added additional support for importance of re-usability.

Show
Duo Zheng added a comment - Added additional support for importance of re-usability.
Hide
Matthew Weier O'Phinney added a comment -

I think the second example makes the most sense. It's simple and concise for the end-user, and relatively easy to support. I'll take a stab at it today.

Show
Matthew Weier O'Phinney added a comment - I think the second example makes the most sense. It's simple and concise for the end-user, and relatively easy to support. I'll take a stab at it today.
Hide
Matthew Weier O'Phinney added a comment -

The second use case is now possible:

class FooControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
    public function setUp()
    {
        $this->bootstrap = new Zend_Application(
            'testing',
            APPLICATION_PATH . '/configs/application.ini'
        );
        parent::setUp();
    }
}

This will be available in 1.9.5, and is currently in trunk and the 1.9 release branch.

Show
Matthew Weier O'Phinney added a comment - The second use case is now possible:
class FooControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
    public function setUp()
    {
        $this->bootstrap = new Zend_Application(
            'testing',
            APPLICATION_PATH . '/configs/application.ini'
        );
        parent::setUp();
    }
}
This will be available in 1.9.5, and is currently in trunk and the 1.9 release branch.

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: