douludi8413 2009-08-26 19:59
浏览 39
已采纳

如何用Zend_Application引导Zend_Test_PHPUnit_ControllerTestCase?

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?

  • 写回答

1条回答 默认 最新

  • duanmaduan1848 2009-08-27 00:15
    关注

    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());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试