Search code examples
phpzend-frameworkzend-controllerzend-layout

Zend_Test_PHPUnit_ControllerTestCase and Zend_Layout, unable to find Layout plugin while running tests


I am starting to write some test cases for controller classes using Zend Framework 1.10.6 and Zend_Test_PHPUnit_ControllerTestCase. I am having problems with one item, which is that while the test cases are running, Zend_Controller_Action_HelperBroker can't find the Layout action helper.

Here are the bare bones of my test case:

require_once 'PHPUnit/Framework.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'controllers/IndexController.php';

class Application_Controllers_IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {

    public $_application;

    protected function setUp() {
        $this->bootstrap = array($this, 'appBootstrap');
        parent::setUp ();
    }

    public function appBootstrap() {
        // Create application, bootstrap, but don't run
        $this->_application = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH . '/configs/application.ini'
        );
        $this->_application->bootstrap();
        $this->getFrontController()->setParams($this->_application->getOptions())
             ->addControllerDirectory(APPLICATION_PATH . '/controllers');
    }

    public function testIndexAction() {
        $this->dispatch('/index/index');
        $this->assertController('index');
        $this->assertAction('index');
    }

}

I get an exception when I run the test case:

Zend_Controller_Action_Exception: Action Helper by name Layout not found

When I comment out the two lines in class Zend_Controller_Action_HelperBroker to try to find the source of this around line 368, I get:

Zend_Loader_PluginLoader_Exception: Plugin by name 'Layout' was not found in the registry; used paths: Zend_Controller_Action_Helper_: Zend/Controller/Action/Helper/

The loading of layout scripts works fine in my application when running, it appears that the correct path or registry for the Zend_Controller_Action_Helper can't be found while running tests under PHPUnit and therefore the Layout plugin can't be loaded.

I have verified that Zend is installed correctly and that Layout.php is in the correct place.

Any ideas?

Del


Solution

  • In you appBootstrap() at the end place this line:

        Zend_Controller_Action_HelperBroker::addHelper(new Zend_Layout_Controller_Action_Helper_Layout);