From 4821984d2b4e1631dc61d3121bd31fb8cda08b58 Mon Sep 17 00:00:00 2001 From: jygaulier Date: Wed, 28 Dec 2022 18:07:01 +0100 Subject: [PATCH] allow multiple calls to closeAccount() (#4201) --- .../Phrasea/Authentication/Authenticator.php | 12 +++++------- .../Phrasea/Authentication/AuthenticatorTest.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/Alchemy/Phrasea/Authentication/Authenticator.php b/lib/Alchemy/Phrasea/Authentication/Authenticator.php index 5a28b7fc43..f1a2386068 100644 --- a/lib/Alchemy/Phrasea/Authentication/Authenticator.php +++ b/lib/Alchemy/Phrasea/Authentication/Authenticator.php @@ -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(); diff --git a/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php b/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php index 7507282856..021568844e 100644 --- a/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php @@ -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