2
我正在为AuthenticationController
实施PHPUnit测试。当我测试的/logout
路线:ZF2测试:断言响应代码“302”失败,实际状态代码为“500”
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是内部服务器错误。我不知道它来自哪里。
任何人有一些想法?
P.S.:
public function setUp()
{
$this->setApplicationConfig(
include '/../../../../../config/application.config.php'
);
parent::setUp();
}
尝试在测试类的顶部添加'protected $ traceError = true;'。它应该为您提供更好的错误响应。 – Ankh
我刚刚做了,但是错误信息完全一样。它不提供更多信息。 – JVerstry
您是否在测试设置中包含了应用程序配置?如果你删除状态码的断言,其他人是否工作? – Ankh