Kim*_*nce 6 php phpunit zend-framework
当用户在没有正确的post参数的情况下访问/ user/validate时,我的Zend应用程序抛出了一个zend异常.(我得到标准的"发生错误"消息,在我的布局中框住).这是故意的.
我现在正试图用PHPUnit来测试这种行为.这是我的测试:
/**
* @expectedException Zend_Exception
*/
public function testEmptyUserValidationParametersCauseException() {
$this->dispatch('/user/validate');
}
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我收到一条消息,说它失败了,"预期异常Zend_Exception".有任何想法吗?
我在文件中有其他测试工作正常......
谢谢!
Zend_Controller_Plugin_ErrorHandler插件为您处理异常,默认的Error_Controller强制执行500重定向,这可能意味着您正在测试的异常不再存在.尝试以下单元测试,看看它是否通过:
public function testUnknownUserRedirectsToErrorPage()
{
$this->dispatch('/user/validate');
$this->assertController('error');
$this->assertAction('error');
$this->assertResponseCode('500');
}
Run Code Online (Sandbox Code Playgroud)
如果这样做,那么它表明,当您呈现错误视图时,异常将不再存在,因为它包含在重定向之前的代码中.