Issues

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

Issue Type: Unit Tests: Problem Created: 2009-10-30T12:22:40.000+0000 Last Updated: 2013-01-21T16:06:56.000+0000 Status: Closed Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Ben Yan (ben_yan) Assignee: Bart McLeod (mcleod@spaceweb.nl) Tags: - Zend_Test_PHPUnit

Related issues: - ZF-12508

Attachments:

Description

<pre class="highlight">
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
    }
}



<pre class="highlight">
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

Posted by Brian Reich (breich) on 2009-12-15T07:48:08.000+0000

I've worked around this issue by applying the following patch to my Bootstrap:

<?php

/** * This file contains the Bootstrap class, which bootstraps resources for the * SUN Tech Web Services application. * * SUN Tech Web Services * PHP 5.2.9, Zend Framework 1.7.5, ExtJS 2.0 * * @author Brian Reich breich@sun-tech.org * @copyright 2008 (C) SUN Area Technical Institute * @category Public * @package Public * @version 2.0 */

/** * Bootstrap extends Zend_Application_Bootstrap_Bootstrap. */ require_once 'Zend/Application/Bootstrap/Bootstrap.php';

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { // ...

/**
 * Initializes the Front Controller
 * 
 * @return Zend_Controller_Front Returns the Front Controller
 */
protected function _initFrontController()
{
    $front = Zend_Controller_Front::getInstance();

    // ...

    /*
    * Fix for ZF-8193
    * Zend_Controller_Action->getInvokeArg('bootstrap') doesn't work
    * under the unit testing environment.
    */
    if($front->getParam('bootstrap') === null)
    {
    $front->setParam('bootstrap', $this);
    }

    return $front;
}

}

Posted by Matthew Turland (elazar) on 2009-12-29T10:55:54.000+0000

The issue is that Zend_Test_PHPUnit_ControllerTestCase doesn't call Zend_Application::run() anywhere. That method is responsible for calling Zend_Application_Bootstrap_Bootstrap::run(), which in turn calls Zend_Controller_Front::setParam() to store a reference to the bootstrap in the front controller as an invoking parameter. I believe Zend_Test_PHPUnit_ControllerTestCase should be modified, likely either in its bootstrap() method or its dispatch() method, to handle this.

Posted by Matthew Weier O'Phinney (matthew) on 2010-01-13T08:19:05.000+0000

Resolved in trunk with r20256.

Posted by miholeus (miholeus) on 2010-10-28T00:37:54.000+0000

Not resolved in last release versions

Posted by Matthew Weier O'Phinney (matthew) on 2010-10-28T05:38:35.000+0000

Actually, it is. Based on what you reported in ZF-10607, you were setting up your testing bootstrap incorrectly.

Posted by Enrico Zimuel (zimuel) on 2011-04-07T16:04:16.000+0000

I'm checking with ZF 1.11.3 and seems that the issue is still present. Here my code of testing:

<pre class="highlight">
class ControllerTestCase
extends Zend_Test_PHPUnit_ControllerTestCase {
  
  protected $application;
  
  public 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();
  }
}

and the following testCase:

<pre class="highlight">
class IndexControllerTest extends ControllerTestCase
{
  public function testBootstrap()
  {
    $this->dispatch('/');
    $this->assertType('Zend_Application_Bootstrap_Bootstrap', $this->_frontController->getParam('bootstrap'));
  }
}

That fails.

Posted by Bart McLeod (mcleod@spaceweb.nl) on 2011-05-08T21:20:30.000+0000

This issue seems to be triggered by this blog post (possibly among others): http://ailoo.net/2009/04/…

I commented on that post hoping that Matthias will adjust the example.

A correct setup for your tests looks like this:

<pre class="highlight">
    public function setUp()
    {
        $this->bootstrap = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH . '/configs/application.ini'
        );

        parent::setUp();
    }

This is taken from Matthew's example in the related issue.

Posted by Bart McLeod (mcleod@spaceweb.nl) on 2011-05-08T21:21:28.000+0000

This is no issue, so I close it.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts