Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.11.0
  • Fix Version/s: None
  • Component/s: Zend_Test_PHPUnit
  • Labels:
    None

Description

IndexController.php
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
    }
}
IndexControllerTest.php
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
    }
}

Issue Links

Activity

Hide
Matthew Weier O'Phinney added a comment - - edited

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.

Show
Matthew Weier O'Phinney added a comment - - edited 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.
Hide
miholeus added a comment -

Thanks. I understand now

Show
miholeus added a comment - Thanks. I understand now

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: