当用户在没有正确post参数的情况下访问/user/validate时,我的Zend应用程序会抛出一个Zend异常。(我得到了标准的"发生错误"消息,在我的布局中框起来(。这是故意的。
我现在正试图用PHPUnit测试这种行为。这是我的测试:
/**
* @expectedException Zend_Exception
*/
public function testEmptyUserValidationParametersCauseException() {
$this->dispatch('/user/validate');
}
当我运行测试时,我收到一条消息,说它失败了,"预期异常Zend_exception"。有什么想法吗?
我在文件中有其他测试,运行良好。。。
谢谢!
public function testUnknownUserRedirectsToErrorPage()
{
$this->dispatch('/user/validate');
$this->assertController('error');
$this->assertAction('error');
$this->assertResponseCode('500');
}
如果这样做有效,则表明当您呈现错误视图时,异常将不再存在,因为它包含在重定向之前的代码中。
好吧,也许它只是因为没有抛出异常而失败?
您是否尝试在没有"@expectedException Zend_Exception"的情况下运行测试?有什么例外吗?