ZF2 Тестирование: сбойный код ответа «302», фактический код состояния «500»,

Я выполняю тесты PHPUnit для AuthenticationController . Когда я тестирую маршрут /logout :

 public function testLogoutActionCanBeAccessed() { $this->dispatch('/logout'); $this->assertResponseStatusCode(302); $this->assertModuleName('Main'); $this->assertControllerName('Main\Controller\Authentication'); $this->assertControllerClass('AuthenticationController'); $this->assertMatchedRouteName('logout'); } из public function testLogoutActionCanBeAccessed() { $this->dispatch('/logout'); $this->assertResponseStatusCode(302); $this->assertModuleName('Main'); $this->assertControllerName('Main\Controller\Authentication'); $this->assertControllerClass('AuthenticationController'); $this->assertMatchedRouteName('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 logoutAction() { $this->loginLogoutService->logout(); return $this->redirect()->toRoute('home'); } 

а также

 public function logout() { $this->authservice->getStorage()->forgetMe(); $this->authservice->clearIdentity(); } 

а также

 $this->authservice = new AuthenticationService(); 

Когда я отлаживаю свое приложение шаг за шагом, $actionResponse состояния $actionResponse равен 302, и приложение работает нормально. 500 – внутренняя ошибка сервера. Я понятия не имею, откуда он.

У кого-то есть идея?

PS :

 public function setUp() { $this->setApplicationConfig( include '/../../../../../config/application.config.php' ); parent::setUp(); } 

Solutions Collecting From Web of "ZF2 Тестирование: сбойный код ответа «302», фактический код состояния «500»,"

У меня была такая же проблема. В моем случае в одном из предыдущих тестов сеанс был уже запущен, и, следовательно, были отправлены заголовки. В результате у меня такой побочный эффект. Один из решений запускает такие тесты отдельно друг от друга. Или, может быть, лучше использовать другой инструмент для тестирования, например, селен для теста.