Getting a “No default module defined for this application” exception while running controller unit tests in zend framework

后端 未结 2 1036
南笙
南笙 2021-02-14 01:18

I have an application with the default directory structure, for an application without custom modules (see structure figure at the end).

I have written a ControllerTes

相关标签:
2条回答
  • 2021-02-14 01:54

    My solution was to include this line after parent::setUp()

    $this->_application->getBootstrap()->getPluginResource('frontcontroller')->init();
    
    0 讨论(0)
  • 2021-02-14 02:11

    This is a known bug.
    Here is my workaround to fix this issue:

    <?php
    require_once 'Zend/Application.php';
    require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
    
    abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
    {
        protected $_application;
    
        protected function setUp()
        {
            $this->bootstrap = array($this, 'appBootstrap');
            parent::setUp();
        }
    
        public function appBootstrap()
        {
            $this->_application = new Zend_Application(APPLICATION_ENV,
                  APPLICATION_PATH . '/configs/application.ini'
            );
            $this->_application->bootstrap();
    
            /**
             * Fix for ZF-8193
             * http://framework.zend.com/issues/browse/ZF-8193
             * Zend_Controller_Action->getInvokeArg('bootstrap') doesn't work
             * under the unit testing environment.
             */
            $front = Zend_Controller_Front::getInstance();
            if($front->getParam('bootstrap') === null) {
                $front->setParam('bootstrap', $this->_application->getBootstrap());
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题