PHPUnit 配置测试
class ControllerTest extends Zend_Test_PHPUnit_ControllerTestCase { public $object; public function setUp() { $this->bootstrap = array($this, 'boostrap'); parent::setUp(); } public function bootstrap(){ $this->application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $this->application->bootstrap(); } public function testIndexAction(){ // body } }
这是测试的班级。我的问题是如何实现 testIndexAction,其中命令提示符上的实际命令是:
php zfrun.php -a ..index
class ControllerTest extends Zend_Test_PHPUnit_ControllerTestCase { public $object; public function setUp() { $this->bootstrap = array($this, 'boostrap'); parent::setUp(); } public function bootstrap(){ $this->application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $this->application->bootstrap(); } public function testIndexAction(){ // body } }
This is the class for the test. My question is how to implement the testIndexAction where the actual command on the command prompt is:
php zfrun.php -a ..index
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在没有看到
zfrun.php
的具体用途的情况下,我只能猜测,而且听起来您需要放弃ControllerTestCase
。ControllerTestCase
旨在模拟通过 Zend 调度程序发送的 HTTP 请求,但您不需要它。相反,您可以尝试通过设置 $argv 来模拟从命令行调用
zfrun.php
,就像它看起来一样并执行zfrun.php
:问题是,这个仅适用于一次测试,假设
zfrun.php
定义了类或函数并且不能多次需要。因此,您需要在新的测试用例基类中执行zfrun.php
所做的任何事情,而不使用zfrun.php
本身。本质上将其代码重构为可重用的测试辅助方法。Without seeing exactly what
zfrun.php
does, I can only guess, and it sounds like you need to ditchControllerTestCase
.ControllerTestCase
is designed to mimic an HTTP request to send through the Zend dispatcher, but you don't need that.Instead, you can try to mimic calling
zfrun.php
from the command line by setting up $argv as it would look and executingzfrun.php
yourself:The problem is that this works for only one test, assuming
zfrun.php
defines classes or functions and cannot be required multiple times. Therefore, you'll need to do whateverzfrun.php
does in a new test case base class without usingzfrun.php
itself. Essentially refactor its code into a reusable test helper method.如果这是对您的主页的测试,请使用“
如果不是,您必须为其提供将触发加载此控制器的路由的 URL。
If this is the test for your home page, use
If not, you'll have to give it the URL that will trigger the route to load this controller.