简体   繁体   中英

How to bootstrap Zend_Test_PHPUnit_ControllerTestCase with Zend_Application?

I am used to writing unit tests in Zend Framework 1.9 using PHPUnit_Framework_TestCase for my application.

Now I am trying to write a unit test based on Zend_Test_PHPUnit_ControllerTestCase by using the bootstrapping by Zend_Application of Zend Framework. But I am unable to get it running.

Here is my nonworking example:

class FamilyControllerTest extends Zend_Test_PHPUnit_ControllerTestCase 
{

    public $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();
    }

    public function testFooOverviewAction() 
    {
        $this->dispatch('/foo/overview');
        $this->assertQueryContentContains('div', 'Silvan');
    }
}

In the official documentation there are only examples that bootstrap the test environment using initialization plugins like it's explained in the official manual .

Any ideas?

You've almost got it, but you have to assign your bootstrap as a parameter to your front controller instance in your test suite--just like Zend_Application automatically does, in a normal environment. In your setUp() add the following line:

$this->getFrontController()->setParam('bootstrap', $this->application->getBootstrap());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM