【问题标题】:Why is "preDispatch" not being reached in my PhpUnit integration tests on Zend Framework controller?为什么在 Zend Framework 控制器上的 PhpUnit 集成测试中没有达到“preDispatch”?
【发布时间】:2014-09-25 06:57:43
【问题描述】:

我有一个扩展 MyCustom_Controller_Action 的 IndexContoller,它扩展 Zend_Controller_Action。

我注意到我的集成测试(当我执行$this->dispatch('/') 时)从未触发我的 IndexController、MyCustom_Controller_Action 或 Zend_Controller_Action 的 preDispatch 方法。但是,这些类的 init() 方法可以访问。

如何修复我的测试设置,以便也调用 preDispatch 函数(就像在我的生产应用程序的正常流程中一样)?

(需要调用它们,否则我无法测试应用程序中实际发生的情况。)

PHPUnit 3.5.15

Zend 框架 1.12

【问题讨论】:

    标签: php zend-framework phpunit integration-testing


    【解决方案1】:

    我错了。正在执行 preDispatch 函数

    我最终通过 Xdebug 证明了这一点。我让 Xdebug 与 Netbeans 和 Phpunit 一起工作。我发现了一个超级有用的个性化分步生成器。我创建了我的 php.ini 的匿名副本并将其上传到 http://xdebug.org/wizard.php 并按照生成的步骤操作,现在我可以通过 Mac 终端运行类似以下内容:

    php -dxdebug.remote_enable=1 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_autostart=On -dxdebug.remote_port=9001 -dxdebug.remote_mode=req /usr/local/opt/php55/bin/phpunit --filter testHeaderLocaleSwitchLoggedOut --bootstrap /code/master/tests/test.php --configuration /code/master/tests/phpunit.xml /code/master/tests/integration
    

    然后,Netbeans 会显示代码在我的断点处停止的位置,并让我慢慢地逐步完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-17
      • 2014-07-22
      • 2012-03-08
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      相关资源
      最近更新 更多