Skip to content

Commit

Permalink
FRW-1817 Fixed false positive test cases with Dynamic Multistore mode…
Browse files Browse the repository at this point in the history
… enabled. (#10862)

FRW-6382 Adjust StoreDependencyHelper and related tests to cover cases when there is no store provided
  • Loading branch information
gechetspr authored Mar 21, 2024
1 parent e43d709 commit 8acfb3c
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 7 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
"require-dev": {
"spryker/code-sniffer": "*",
"spryker/container": "*",
"spryker/country": "*",
"spryker/currency": "*",
"spryker/locale": "*",
"spryker/propel": "*",
"spryker/quote": "*",
"spryker/store-storage": "*",
"spryker/testify": "*"
},
"suggest": {
Expand All @@ -35,7 +38,8 @@
"autoload": {
"psr-4": {
"Spryker\\": "src/Spryker/",
"SprykerTest\\Shared\\Store\\Helper\\": "tests/SprykerTest/Shared/Store/_support/Helper/"
"SprykerTest\\Shared\\Store\\Helper\\": "tests/SprykerTest/Shared/Store/_support/Helper/",
"SprykerTest\\Zed\\Store\\Helper\\": "tests/SprykerTest/Zed/Store/_support/Helper/"
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Spryker/Zed/Store/Business/Model/StoreReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getAllStores()
}

$storeTransfers = $this->getStoreTransfersByStoreNames(
$this->storeRepository->getStoreNamesByCriteria(new StoreCriteriaTransfer()),
array_filter($this->storeRepository->getStoreNamesByCriteria(new StoreCriteriaTransfer())),
);
$stores = $this->storeExpander->expandStores($storeTransfers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class StoreDataHelper extends Module
*/
protected const DEFAULT_STORE = 'DE';

/**
* @var string
*/
protected const DEFAULT_STORE_AT = 'AT';

/**
* @param \Codeception\TestInterface $test
*
Expand Down Expand Up @@ -68,7 +73,7 @@ public function haveStore(array $storeOverride = [], bool $expandStore = true)
(new StoreCache())->cacheStore($storeTransfer);
}

$this->getDataCleanupHelper()->addCleanup(function (): void {
$this->getDataCleanupHelper()->addCleanup(function () use ($storeTransfer): void {
$this->clearStoreCache();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
use Codeception\Stub;
use Codeception\TestInterface;
use Generated\Shared\Transfer\StoreTransfer;
use Spryker\Zed\Store\StoreDependencyProvider;
use Spryker\Client\Store\StoreDependencyProvider;
use Spryker\Client\StoreExtension\Dependency\Plugin\StoreExpanderPluginInterface;
use Spryker\Client\StoreStorage\Plugin\Store\StoreStorageStoreExpanderPlugin;
use Spryker\Zed\Country\Communication\Plugin\Store\CountryStoreCollectionExpanderPlugin;
use Spryker\Zed\Currency\Communication\Plugin\Store\CurrencyStoreCollectionExpanderPlugin;
use Spryker\Zed\Locale\Communication\Plugin\Store\LocaleStoreCollectionExpanderPlugin;
use Spryker\Zed\Store\StoreDependencyProvider as ZedStoreDependencyProvider;
use Spryker\Zed\StoreExtension\Dependency\Plugin\StoreCollectionExpanderPluginInterface;
use SprykerTest\Service\Container\Helper\ContainerHelperTrait;
use SprykerTest\Shared\Testify\Helper\DependencyHelperTrait;
Expand Down Expand Up @@ -72,8 +78,14 @@ public function _before(TestInterface $test)
->getContainer()
->set(static::SERVICE_LOCALE, static::LOCALE_EN);

$this->setDependency(StoreDependencyProvider::PLUGINS_STORE_COLLECTION_EXPANDER, [
$this->createStoreCurrencyLocaleExpandedMock(),
$this->setDependency(ZedStoreDependencyProvider::PLUGINS_STORE_COLLECTION_EXPANDER, [
new CurrencyStoreCollectionExpanderPlugin(),
new CountryStoreCollectionExpanderPlugin(),
new LocaleStoreCollectionExpanderPlugin(),
]);

$this->setDependency(StoreDependencyProvider::PLUGINS_STORE_EXPANDER, [
new StoreStorageStoreExpanderPlugin(),
]);
}

Expand All @@ -94,4 +106,22 @@ protected function createStoreCurrencyLocaleExpandedMock(): StoreCollectionExpan
'expand' => [$storeTransfer],
]);
}

/**
* @return \Spryker\Client\StoreExtension\Dependency\Plugin\StoreExpanderPluginInterface
*/
protected function createStoreStorageStoreExpanderMock(): StoreExpanderPluginInterface
{
$storeTransfer = (new StoreTransfer())
->setIdStore(static::STORE_ID)
->setName(static::DEFAULT_STORE)
->setDefaultCurrencyIsoCode(static::DEFAULT_CURRENCY)
->setDefaultLocaleIsoCode(static::LOCALE_EN)
->setAvailableLocaleIsoCodes([static::LOCALE_EN, static::LOCALE_DE])
->setAvailableCurrencyIsoCodes([static::DEFAULT_CURRENCY]);

return Stub::makeEmpty(StoreExpanderPluginInterface::class, [
'expand' => [$storeTransfer],
]);
}
}
114 changes: 114 additions & 0 deletions tests/SprykerTest/Zed/Store/_support/Helper/StoreDependencyHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?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\Zed\Store\Helper;

use Codeception\Module;
use Codeception\TestInterface;
use Generated\Shared\Transfer\StoreTransfer;
use Spryker\Zed\Country\Communication\Plugin\Store\CountryStoreCollectionExpanderPlugin;
use Spryker\Zed\Currency\Communication\Plugin\Store\CurrencyStoreCollectionExpanderPlugin;
use Spryker\Zed\Locale\Communication\Plugin\Store\LocaleStoreCollectionExpanderPlugin;
use Spryker\Zed\Store\StoreDependencyProvider;
use SprykerTest\Service\Container\Helper\ContainerHelperTrait;
use SprykerTest\Shared\Testify\Helper\DependencyHelperTrait;

class StoreDependencyHelper extends Module
{
use ContainerHelperTrait;
use DependencyHelperTrait;

/**
* @var string
*/
protected const SERVICE_STORE = 'store';

/**
* @var string
*/
protected const SERVICE_LOCALE = 'locale';

/**
* @var string
*/
protected const DEFAULT_STORE = 'DE';

/**
* @var int
*/
protected const STORE_ID = 1;

/**
* @var string
*/
protected const DEFAULT_CURRENCY = 'EUR';

/**
* @var string
*/
protected const LOCALE_DE = 'de_DE';

/**
* @var string
*/
protected const LOCALE_EN = 'en_US';

/**
* @param \Codeception\TestInterface $test
*
* @return void
*/
public function _before(TestInterface $test)
{
parent::_before($test);
$this->getContainerHelper()
->getContainer()
->set(static::SERVICE_LOCALE, static::LOCALE_EN);

$this->setDependency(StoreDependencyProvider::PLUGINS_STORE_COLLECTION_EXPANDER, [
new CurrencyStoreCollectionExpanderPlugin(),
new CountryStoreCollectionExpanderPlugin(),
new LocaleStoreCollectionExpanderPlugin(),
]);
}

/**
* @param \Codeception\TestInterface $test
*
* @return void
*/
public function _after(TestInterface $test)
{
parent::_after($test);
if ($this->getContainerHelper()->getContainer()->has(static::SERVICE_LOCALE)) {
$this->getContainerHelper()->getContainer()->remove(static::SERVICE_LOCALE);
}
$this->removeCurrentStore();
}

/**
* @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer
*
* @return void
*/
public function addCurrentStore(StoreTransfer $storeTransfer): void
{
$this->getContainerHelper()
->getContainer()
->set(static::SERVICE_STORE, $storeTransfer->getName());
}

/**
* @return void
*/
public function removeCurrentStore(): void
{
if ($this->getContainerHelper()->getContainer()->has(static::SERVICE_STORE)) {
$this->getContainerHelper()->getContainer()->remove(static::SERVICE_STORE);
}
}
}
2 changes: 1 addition & 1 deletion tests/SprykerTest/Zed/Store/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ suites:
- \SprykerTest\Shared\Store\Helper\StoreDataHelper
- \SprykerTest\Shared\Testify\Helper\DataCleanupHelper
- \SprykerTest\Service\Container\Helper\ContainerHelper
- \SprykerTest\Shared\Store\Helper\StoreDependencyHelper
- \SprykerTest\Zed\Store\Helper\StoreDependencyHelper
- \SprykerTest\Shared\Locale\Helper\LocaleDependencyHelper
- \SprykerTest\Shared\Store\Helper\StoreReferenceHelper

Expand Down

0 comments on commit 8acfb3c

Please sign in to comment.