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