Skip to content

Commit

Permalink
MSI-757: Add Inventory Index invalidation when Source is enabled or d…
Browse files Browse the repository at this point in the history
…isabled.
  • Loading branch information
p-bystritsky committed Apr 4, 2018
1 parent f06aeed commit e2374a6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function aroundSave(
) {
$invalidationRequired = $this->isInvalidationRequiredForSource->execute(
$source->getSourceCode(),
$source->isEnabled()
(bool)$source->isEnabled()
);

$proceed($source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function indexerInvalidationDataProvider(): array
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*
* @dataProvider sourceDoesNotHaveAnyRelationsDataProvider
* @dataProvider sourceDoesNotHaveAllRelationsDataProvider
* @param string $sourceCode
* @param bool $enable
* @param bool $expectedValid
Expand All @@ -93,10 +93,56 @@ public function testIndexerInvalidationIfSourceDoesNotHaveAnyRelations(
$this->assertEquals($expectedValid, $this->indexer->isValid());
}

/**
* Tests Source enabling and disabling when no Stocks are connected to current Source.
*
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*
* @dataProvider sourceDoesNotHaveAllRelationsDataProvider
* @param string $sourceCode
* @param bool $enable
* @param bool $expectedValid
*/
public function testIndexerInvalidationIfSourceDoesNotHaveStockLinks(
string $sourceCode,
bool $enable,
bool $expectedValid
) {
$this->setSourceEnabledStatus($sourceCode, $enable);

$this->assertEquals($expectedValid, $this->indexer->isValid());
}

/**
* Tests Source enabling and disabling when no Source Items are connected to current Source.
*
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*
* @dataProvider sourceDoesNotHaveAllRelationsDataProvider
* @param string $sourceCode
* @param bool $enable
* @param bool $expectedValid
*/
public function testIndexerInvalidationIfSourceDoesNotHaveSourceItems(
string $sourceCode,
bool $enable,
bool $expectedValid
) {
$this->setSourceEnabledStatus($sourceCode, $enable);

$this->assertEquals($expectedValid, $this->indexer->isValid());
}

/**
* @return array
*/
public function sourceDoesNotHaveAnyRelationsDataProvider(): array
public function sourceDoesNotHaveAllRelationsDataProvider(): array
{
return [
['eu-1', true, true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
declare(strict_types=1);

use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\InventoryIndexer\Indexer\InventoryIndexer;
use Magento\TestFramework\Helper\Bootstrap;

/** @var IndexerInterface $indexer */
$indexer = Bootstrap::getObjectManager()->create(IndexerInterface::class);
$indexer->load(InventoryIndexer::INDEXER_ID);
/** @var IndexerRegistry $indexerRegistry */
$indexerRegistry = Bootstrap::getObjectManager()->get(IndexerRegistry::class);
$indexer = $indexerRegistry->get(InventoryIndexer::INDEXER_ID);
$indexer->reindexAll();

0 comments on commit e2374a6

Please sign in to comment.