如何用Zend_Application引导Zend_Test_PHPUnit_ControllerTestCase?

时间:2009-08-26 19:59:09

标签: php zend-framework

我习惯使用PHPUnit_Framework_TestCase为我的应用程序在Zend Framework 1.9中编写单元测试。

现在我尝试使用Zend Framework的Zend_Test_PHPUnit_ControllerTestCase引导来编写基于Zend_Application的单元测试。但我无法让它运行。

这是我的非工作示例:

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');
    }
}

在官方文档中,只有使用初始化插件(例如explained in the official manual)引导测试环境的示例。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

你几乎得到了它,但是你必须将你的引导程序作为参数分配给你的测试套件中的前端控制器实例 - 就像Zend_Application在正常环境中一样。在setUp()添加以下行:

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