-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FRW-1817 Adjusted Dynamic Multistore Test Coverage (#10800)
FRW-1817 Adjusted Dynamic Multistore Test Coverage
- Loading branch information
Showing
3 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
tests/SprykerTest/Client/MultiCart/Storage/MultiCartStorageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Client\MultiCart\Storage; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\Transfer\QuoteCollectionTransfer; | ||
use Generated\Shared\Transfer\QuoteTransfer; | ||
use Generated\Shared\Transfer\StoreTransfer; | ||
use Spryker\Client\MultiCart\Dependency\Client\MultiCartToSessionClientInterface; | ||
use Spryker\Client\MultiCart\Dependency\Client\MultiCartToStoreClientInterface; | ||
use Spryker\Client\MultiCart\MultiCartConfig; | ||
use Spryker\Client\MultiCart\Storage\MultiCartStorage; | ||
use SprykerTest\Client\MultiCart\MultiCartClientTester; | ||
|
||
/** | ||
* Auto-generated group annotations | ||
* | ||
* @group SprykerTest | ||
* @group Client | ||
* @group MultiCart | ||
* @group Storage | ||
* @group MultiCartStorageTest | ||
* Add your own group annotations below this line | ||
*/ | ||
class MultiCartStorageTest extends Unit | ||
{ | ||
/** | ||
* @var \SprykerTest\Client\MultiCart\MultiCartClientTester | ||
*/ | ||
protected MultiCartClientTester $tester; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testSetQuoteCollectionSetsQuoteKeyWithCurrentStorePrefixIfDynamicStoreIsEnabled(): void | ||
{ | ||
if ($this->tester->isDynamicStoreEnabled() === false) { | ||
$this->markTestSkipped('This test requires DynamicStore to be enabled.'); | ||
} | ||
|
||
//Arrange | ||
$quoteCollectionTransfer = (new QuoteCollectionTransfer()) | ||
->addQuote($this->tester->haveQuote()) | ||
->addQuote($this->tester->haveQuote()); | ||
$storeTransfer = $this->tester->getLocator()->store()->client()->getCurrentStore(); | ||
$expectedSessionKey = sprintf('%s_%s', $storeTransfer->getName(), $this->tester::SESSION_KEY_QUOTE_COLLECTION); | ||
|
||
//Assert | ||
$storeClientMock = $this->createStoreClientMock(); | ||
$storeClientMock->expects($this->once()) | ||
->method('getCurrentStore') | ||
->willReturn($storeTransfer); | ||
|
||
$sessionClientMock = $this->createSessionClientMock(); | ||
$sessionClientMock->expects($this->once()) | ||
->method('set') | ||
->willReturnCallback(function (string $quoteCollectionKey) use ($expectedSessionKey) { | ||
$this->assertSame($expectedSessionKey, $quoteCollectionKey); | ||
}); | ||
|
||
//Act | ||
$multiCartStorage = new MultiCartStorage( | ||
$sessionClientMock, | ||
$storeClientMock, | ||
$this->createMultiCartConfig(), | ||
); | ||
$multiCartStorage->setQuoteCollection($quoteCollectionTransfer); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testSetQuoteCollectionSetsQuoteKeyWithoutCurrentStorePrefixIfDynamicStoreIsDisabled(): void | ||
{ | ||
if ($this->tester->isDynamicStoreEnabled() === true) { | ||
$this->markTestSkipped('This test requires DynamicStore to be disabled.'); | ||
} | ||
|
||
//Arrange | ||
$quoteCollectionTransfer = (new QuoteCollectionTransfer()) | ||
->addQuote($this->tester->haveQuote()) | ||
->addQuote($this->tester->haveQuote()); | ||
$storeTransfer = $this->tester->getLocator()->store()->client()->getCurrentStore(); | ||
|
||
//Assert | ||
$storeClientMock = $this->createStoreClientMock(); | ||
$storeClientMock->expects($this->never()) | ||
->method('getCurrentStore'); | ||
|
||
$sessionClientMock = $this->createSessionClientMock(); | ||
$sessionClientMock->expects($this->once()) | ||
->method('set') | ||
->willReturnCallback(function (string $quoteCollectionKey) { | ||
$this->assertSame($this->tester::SESSION_KEY_QUOTE_COLLECTION, $quoteCollectionKey); | ||
}); | ||
|
||
//Act | ||
$multiCartStorage = new MultiCartStorage( | ||
$sessionClientMock, | ||
$storeClientMock, | ||
$this->createMultiCartConfig(), | ||
); | ||
$multiCartStorage->setQuoteCollection($quoteCollectionTransfer); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Client\MultiCart\Dependency\Client\MultiCartToSessionClientInterface | ||
*/ | ||
protected function createSessionClientMock(): MultiCartToSessionClientInterface | ||
{ | ||
return $this->createMock(MultiCartToSessionClientInterface::class); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Client\MultiCart\Dependency\Client\MultiCartToStoreClientInterface | ||
*/ | ||
protected function createStoreClientMock(): MultiCartToStoreClientInterface | ||
{ | ||
$storeClientMock = $this->createMock(MultiCartToStoreClientInterface::class); | ||
$storeClientMock->expects($this->once()) | ||
->method('isDynamicStoreEnabled') | ||
->willReturn($this->tester->isDynamicStoreEnabled()); | ||
|
||
return $storeClientMock; | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Client\MultiCart\MultiCartConfig | ||
*/ | ||
protected function createMultiCartConfig(): MultiCartConfig | ||
{ | ||
$configMock = $this->createMock(MultiCartConfig::class); | ||
$configMock->expects($this->once()) | ||
->method('getQuoteFieldsAllowedForCustomerQuoteCollectionInSession') | ||
->willReturn([ | ||
QuoteTransfer::ID_QUOTE, | ||
QuoteTransfer::STORE => [ | ||
StoreTransfer::ID_STORE, | ||
StoreTransfer::NAME, | ||
], | ||
]); | ||
|
||
return $configMock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters