Issues

ZF-10607: CLONE -Zend_Controller_Action->getInvokeArg('bootstrap') doesn't work under the unit testing environment

Description


class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        var_dump($this->getInvokeArg('bootstrap')); // It should NOT output NULL, but an instance of class "Zend_Application_Bootstrap_Bootstrap" under the unit testing environment
    }
}

class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{

    public $application;

    public function setUp()
    {
        $this->application = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH . '/configs/application.ini'
        );

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

    public function appBootstrap()
    {
        $this->application->bootstrap();
    }

    public function testIndexAction() {
        $this->dispatch('/');
        $this->assertType('Zend_Application_Bootstrap_Bootstrap', $this->_frontController->getParam('bootstrap')); // FAILURE
    }
}

Comments

You're doing it wrong.

Simply assign the Zend_Application instance to the $bootstrap property.


class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{

    public $application;

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

    public function testIndexAction() {
        $this->dispatch('/');
        $this->assertType('Zend_Application_Bootstrap_Bootstrap', $this->frontController->getParam('bootstrap')); // SUCCESS
    }
}

The above works perfectly.

Thanks. I understand now