I am implementing PHPUnit tests for an AuthenticationController
. When I test the /logout
route:
public function testLogoutActionCanBeAccessed()
{
$this->dispatch('/logout');
$this->assertResponseStatusCode(302);
$this->assertModuleName('Main');
$this->assertControllerName('Main\Controller\Authentication');
$this->assertControllerClass('AuthenticationController');
$this->assertMatchedRouteName('logout');
}
I get the following error message:
There was 1 failure:
1) MainTest\Controller\AuthenticationControllerTest::testLogoutActionCanBeAccessed
Failed asserting response code "302", actual status code is "500"
The logout code is the following:
public function logoutAction()
{
$this->loginLogoutService->logout();
return $this->redirect()->toRoute('home');
}
and
public function logout() {
$this->authservice->getStorage()->forgetMe();
$this->authservice->clearIdentity();
}
and
$this->authservice = new AuthenticationService();
When I debug my app step-by-step, the $actionResponse
status code is 302 and the application works fine. 500 is internal server error. I have no idea where it is coming from.
Anyone has some idea?
P.S.:
public function setUp()
{
$this->setApplicationConfig(
include '/../../../../../config/application.config.php'
);
parent::setUp();
}