Skip to content

Commit 0e0722d

Browse files
committed
OXDEV-9078 Remove unnecessary session constant container class
Signed-off-by: Anton Fedurtsya <anton@fedurtsya.com>
1 parent 7686eb0 commit 0e0722d

5 files changed

Lines changed: 12 additions & 28 deletions

File tree

src/Authentication/Service/InternalRedirectService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
use OxidEsales\Eshop\Core\Config;
1313
use OxidEsales\EshopCommunity\Internal\Framework\Session\SessionInterface;
14-
use OxidEsales\SecurityModule\Authentication\Session\SessionKeys;
1514

1615
readonly class InternalRedirectService implements InternalRedirectServiceInterface
1716
{
17+
public const AUTH_REDIRECT_URL = 'otp_target_url';
1818
public function __construct(
1919
private SessionInterface $session,
2020
private Config $config,
@@ -23,7 +23,7 @@ public function __construct(
2323

2424
public function getRedirectUrl(): string
2525
{
26-
$storedUrl = $this->session->get(SessionKeys::AUTH_REDIRECT_URL);
26+
$storedUrl = $this->session->get(self::AUTH_REDIRECT_URL);
2727

2828
if ($storedUrl && $this->isInternalUrl($storedUrl)) {
2929
return $storedUrl;

src/Authentication/Session/SessionKeys.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Authentication/Subscriber/StoreCurrentUrlSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use OxidEsales\Eshop\Core\Request;
1414
use OxidEsales\EshopCommunity\Internal\Framework\Session\SessionInterface;
1515
use OxidEsales\EshopCommunity\Internal\Transition\ShopEvents\ViewRenderedEvent;
16-
use OxidEsales\SecurityModule\Authentication\Session\SessionKeys;
16+
use OxidEsales\SecurityModule\Authentication\Service\InternalRedirectService;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1818

1919
readonly class StoreCurrentUrlSubscriber implements EventSubscriberInterface
@@ -63,7 +63,7 @@ public function onViewRendered(ViewRenderedEvent $event): void
6363

6464
$currentUrl = $this->getCurrentPageUrl();
6565
if ($currentUrl) {
66-
$this->session->set(SessionKeys::AUTH_REDIRECT_URL, $currentUrl);
66+
$this->session->set(InternalRedirectService::AUTH_REDIRECT_URL, $currentUrl);
6767
}
6868
}
6969

tests/Unit/Authentication/Service/InternalRedirectServiceTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use OxidEsales\Eshop\Core\Config;
1313
use OxidEsales\EshopCommunity\Internal\Framework\Session\SessionInterface;
1414
use OxidEsales\SecurityModule\Authentication\Service\InternalRedirectService;
15-
use OxidEsales\SecurityModule\Authentication\Session\SessionKeys;
1615
use PHPUnit\Framework\TestCase;
1716

1817
class InternalRedirectServiceTest extends TestCase
@@ -24,7 +23,7 @@ public function testGetRedirectUrlReturnsStoredUrlWhenInternal(): void
2423

2524
$sessionStub = $this->createStub(SessionInterface::class);
2625
$sessionStub->method('get')
27-
->with(SessionKeys::AUTH_REDIRECT_URL)
26+
->with(InternalRedirectService::AUTH_REDIRECT_URL)
2827
->willReturn($storedUrl);
2928

3029
$configStub = $this->createStub(Config::class);
@@ -44,7 +43,7 @@ public function testGetRedirectUrlReturnsStoredUrlWhenMatchesSslShopUrl(): void
4443

4544
$sessionStub = $this->createStub(SessionInterface::class);
4645
$sessionStub->method('get')
47-
->with(SessionKeys::AUTH_REDIRECT_URL)
46+
->with(InternalRedirectService::AUTH_REDIRECT_URL)
4847
->willReturn($storedUrl);
4948

5049
$configStub = $this->createStub(Config::class);
@@ -64,7 +63,7 @@ public function testGetRedirectUrlReturnsShopHomeWhenStoredUrlIsExternal(): void
6463

6564
$sessionStub = $this->createStub(SessionInterface::class);
6665
$sessionStub->method('get')
67-
->with(SessionKeys::AUTH_REDIRECT_URL)
66+
->with(InternalRedirectService::AUTH_REDIRECT_URL)
6867
->willReturn($externalUrl);
6968

7069
$configStub = $this->createStub(Config::class);
@@ -83,7 +82,7 @@ public function testGetRedirectUrlReturnsShopHomeWhenNoStoredUrl(): void
8382

8483
$sessionStub = $this->createStub(SessionInterface::class);
8584
$sessionStub->method('get')
86-
->with(SessionKeys::AUTH_REDIRECT_URL)
85+
->with(InternalRedirectService::AUTH_REDIRECT_URL)
8786
->willReturn(null);
8887

8988
$configStub = $this->createStub(Config::class);
@@ -100,7 +99,7 @@ public function testGetRedirectUrlReturnsShopHomeWhenStoredUrlIsEmpty(): void
10099

101100
$sessionStub = $this->createStub(SessionInterface::class);
102101
$sessionStub->method('get')
103-
->with(SessionKeys::AUTH_REDIRECT_URL)
102+
->with(InternalRedirectService::AUTH_REDIRECT_URL)
104103
->willReturn('');
105104

106105
$configStub = $this->createStub(Config::class);

tests/Unit/Authentication/Subscriber/StoreCurrentUrlSubscriberTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use OxidEsales\EshopCommunity\Application\Controller\FrontendController;
1616
use OxidEsales\EshopCommunity\Internal\Framework\Session\SessionInterface;
1717
use OxidEsales\EshopCommunity\Internal\Transition\ShopEvents\ViewRenderedEvent;
18-
use OxidEsales\SecurityModule\Authentication\Session\SessionKeys;
18+
use OxidEsales\SecurityModule\Authentication\Service\InternalRedirectService;
1919
use OxidEsales\SecurityModule\Authentication\Subscriber\StoreCurrentUrlSubscriber;
2020
use PHPUnit\Framework\TestCase;
2121

@@ -47,7 +47,7 @@ public function testOnViewRenderedStoresCurrentUrl(): void
4747
$sessionMock = $this->createMock(SessionInterface::class);
4848
$sessionMock->expects($this->once())
4949
->method('set')
50-
->with(SessionKeys::AUTH_REDIRECT_URL, $currentUrl);
50+
->with(InternalRedirectService::AUTH_REDIRECT_URL, $currentUrl);
5151

5252
$sut = $this->getSut(
5353
session: $sessionMock,
@@ -259,7 +259,7 @@ public function testOnViewRenderedStoresUrlWithOtherFunction(): void
259259
$sessionMock = $this->createMock(SessionInterface::class);
260260
$sessionMock->expects($this->once())
261261
->method('set')
262-
->with(SessionKeys::AUTH_REDIRECT_URL, $currentUrl);
262+
->with(InternalRedirectService::AUTH_REDIRECT_URL, $currentUrl);
263263

264264
$sut = $this->getSut(
265265
session: $sessionMock,

0 commit comments

Comments
 (0)