【发布时间】:2015-11-30 10:08:07
【问题描述】:
我正在为AuthenticationController 实施 PHPUnit 测试。当我测试/logout 路由时:
public function testLogoutActionCanBeAccessed()
{
$this->dispatch('/logout');
$this->assertResponseStatusCode(302);
$this->assertModuleName('Main');
$this->assertControllerName('Main\Controller\Authentication');
$this->assertControllerClass('AuthenticationController');
$this->assertMatchedRouteName('logout');
}
我收到以下错误消息:
There was 1 failure:
1) MainTest\Controller\AuthenticationControllerTest::testLogoutActionCanBeAccessed
Failed asserting response code "302", actual status code is "500"
注销代码如下:
public function logoutAction()
{
$this->loginLogoutService->logout();
return $this->redirect()->toRoute('home');
}
和
public function logout() {
$this->authservice->getStorage()->forgetMe();
$this->authservice->clearIdentity();
}
和
$this->authservice = new AuthenticationService();
当我逐步调试我的应用程序时,$actionResponse 状态码为 302,应用程序运行正常。 500 是内部服务器错误。我不知道它是从哪里来的。
有人有什么想法吗?
附注:
public function setUp()
{
$this->setApplicationConfig(
include '/../../../../../config/application.config.php'
);
parent::setUp();
}
【问题讨论】:
-
尝试在测试类的顶部添加
protected $traceError = true;。它应该为您提供更好的错误响应。 -
我刚做了,但错误信息完全一样。它没有提供更多信息。
-
您是否在测试设置中包含了应用程序配置?如果您删除状态代码的断言,其他的是否有效?
-
是的,请参阅我的问题更新。其他路线测试有效。只有这个失败了。
-
什么更新?你能告诉我你的
setUp()函数吗?
标签: php zend-framework2 phpunit