allow multiple calls to closeAccount() (#4201)

This commit is contained in:
jygaulier
2022-12-28 18:07:01 +01:00
committed by GitHub
parent 2bcb96759f
commit 4821984d2b
2 changed files with 13 additions and 15 deletions

View File

@@ -133,13 +133,11 @@ class Authenticator
*/
public function closeAccount()
{
if (!$this->session->has('session_id')) {
throw new RuntimeException('No session to close.');
}
if (null !== $session = $this->app['repo.sessions']->find($this->session->get('session_id'))) {
$this->em->remove($session);
$this->em->flush();
if ($this->session->has('session_id')) {
if (null !== $session = $this->app['repo.sessions']->find($this->session->get('session_id'))) {
$this->em->remove($session);
$this->em->flush();
}
}
$this->session->invalidate();

View File

@@ -214,14 +214,14 @@ class AuthenticatorTest extends \PhraseanetTestCase
$this->assertNull($authenticator->getUser());
}
public function testCloseAccountWhenNoSessionThrowsAnException()
{
$app = $this->getApplication();
$authenticator = new Authenticator($app, $app['browser'], $app['session'], $app['orm.em']);
$this->setExpectedException('Alchemy\Phrasea\Exception\RuntimeException', 'No session to close.');
$authenticator->closeAccount();
}
// public function testCloseAccountWhenNoSessionThrowsAnException()
// {
// $app = $this->getApplication();
//
// $authenticator = new Authenticator($app, $app['browser'], $app['session'], $app['orm.em']);
// $this->setExpectedException('Alchemy\Phrasea\Exception\RuntimeException', 'No session to close.');
// $authenticator->closeAccount();
// }
/**
* @covers Alchemy\Phrasea\Authentication\Authenticator::isAuthenticated