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 0a28605 commit 43726cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
24 changes: 14 additions & 10 deletions tests/SprykerTest/Zed/Product/Business/ProductFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Generated\Shared\Transfer\ProductPublisherConfigTransfer;
use Generated\Shared\Transfer\ProductUpdatedTransfer;
use Generated\Shared\Transfer\ProductUrlCriteriaFilterTransfer;
use Generated\Shared\Transfer\StoreTransfer;
use Spryker\Shared\Product\ProductConstants;
use Spryker\Zed\Product\Business\Exception\ProductConcreteExistsException;
use Spryker\Zed\Product\Business\Exception\ProductPublisherEventNameMismatchException;
Expand Down Expand Up @@ -50,6 +51,11 @@ class ProductFacadeTest extends Unit
*/
protected $tester;

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

/**
* @var array<string, string>
*/
Expand Down Expand Up @@ -285,7 +291,7 @@ public function testGetProductConcretesByCriteria(): void
$productConcreteTransfer = $this->tester->getFacade()->findProductConcreteById($productConcreteIds[0]);
$productCriteriaTransferWithExistingStore = new ProductCriteriaTransfer();
$productCriteriaTransferWithExistingStore->setIdStore(
$this->tester->getStoreFacade()->getCurrentStore()->getIdStore(),
$this->tester->haveStore([StoreTransfer::NAME => static::DEFAULT_STORE])->getIdStore(),
);
$productCriteriaTransferWithExistingStore->setIsActive(true);
$productCriteriaTransferWithExistingStore->setSkus([$productConcreteTransfer->getSku()]);
Expand Down Expand Up @@ -638,25 +644,23 @@ public function testProductDeletedEventNotPublishedToMessageBrokerIfProductsList
public function testProductExportEventsSuccessfullyTriggeredWithFullAcceptanceCriteria(): void
{
// Arrange
$productConcreteTransfer1 = $this->tester->haveFullProduct();
$productConcreteTransfer2 = $this->tester->haveFullProduct();
$productConcreteTransfer = $this->tester->haveFullProduct();

$storeTransfer = $this->tester->getStoreFacade()->getCurrentStore();
$storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => static::DEFAULT_STORE]);

$this->tester->deleteProductFromStore($productConcreteTransfer2, $storeTransfer);
$this->tester->deleteProductFromStore($productConcreteTransfer, $storeTransfer);

$productExportCriteriaTransfer = (new ProductExportCriteriaTransfer())
->setStoreReference($storeTransfer->getStoreReference());
$productExportCriteriaTransfer = (new ProductExportCriteriaTransfer());

// Assert
$this->eventFacade
->expects($this->atLeastOnce())
->method('triggerBulk')
->with(ProductEvents::PRODUCT_CONCRETE_EXPORT, $this->callback(
function ($transfers) use ($productConcreteTransfer2) {
function ($transfers) use ($productConcreteTransfer) {
$this->assertNotEmpty($transfers);
$this->assertInstanceOf(EventEntityTransfer::class, $transfers[0]);
$this->assertNotContains($productConcreteTransfer2, $transfers);
$this->assertNotContains($productConcreteTransfer, $transfers);

return true;
},
Expand All @@ -675,7 +679,7 @@ public function testProductExportEventsSuccessfullyTriggeredWithEmptyAcceptanceC
$productConcreteTransfer1 = $this->tester->haveFullProduct();
$productConcreteTransfer2 = $this->tester->haveFullProduct();

$storeTransfer = $this->tester->getStoreFacade()->getCurrentStore();
$storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => static::DEFAULT_STORE]);

$this->tester->deleteProductFromStore($productConcreteTransfer2, $storeTransfer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class ProductBusinessTester extends Actor
{
use _generated\ProductBusinessTesterActions;

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

/**
* @var array<int>
*/
Expand Down Expand Up @@ -227,7 +232,7 @@ protected function createProductAbstractTransfer(string $sku): ProductAbstractTr
*/
protected function createStoreRelationTransfer(ProductAbstractTransfer $productAbstractTransfer): StoreRelationTransfer
{
$storeTransfer = $this->getStoreFacade()->getCurrentStore();
$storeTransfer = $this->haveStore([StoreTransfer::NAME => static::DEFAULT_STORE]);

$storeRelationTransfer = new StoreRelationTransfer();
$storeRelationTransfer->setIdEntity($productAbstractTransfer->getIdProductAbstract());
Expand Down
2 changes: 1 addition & 1 deletion tests/SprykerTest/Zed/Product/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ suites:
- \SprykerTest\Zed\Locale\Helper\LocaleDataHelper
- \SprykerTest\Shared\Testify\Helper\TableRelationsCleanupHelper
- \SprykerTest\Service\Container\Helper\ContainerHelper
- \SprykerTest\Shared\Store\Helper\StoreDependencyHelper
- \SprykerTest\Zed\Store\Helper\StoreDependencyHelper
- \SprykerTest\Shared\Store\Helper\StoreDataHelper
- \SprykerTest\Shared\Store\Helper\StoreReferenceHelper
- \SprykerTest\Shared\Product\Helper\ProductDataHelper
Expand Down

0 comments on commit 43726cf

Please sign in to comment.