Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceIndexerTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 use PHPUnit\Framework\TestCase;
15 
16 class SourceIndexerTest extends TestCase
17 {
21  private $sourceIndexer;
22 
26  private $getStockItemData;
27 
31  private $removeIndexData;
32 
33  protected function setUp()
34  {
35  $this->sourceIndexer = Bootstrap::getObjectManager()->get(SourceIndexer::class);
36  $this->getStockItemData = Bootstrap::getObjectManager()->get(GetStockItemData::class);
37 
38  $this->removeIndexData = Bootstrap::getObjectManager()->get(RemoveIndexData::class);
39  $this->removeIndexData->execute([10, 20, 30]);
40  }
41 
45  protected function tearDown()
46  {
47  $this->removeIndexData->execute([10, 20, 30]);
48  }
49 
68  public function testReindexRow(string $sku, int $stockId, $expectedData)
69  {
70  $this->sourceIndexer->executeRow('eu-1');
71 
72  $stockItemData = $this->getStockItemData->execute($sku, $stockId);
73  self::assertEquals($expectedData, $stockItemData);
74  }
75 
79  public function reindexRowDataProvider(): array
80  {
81  return [
84  ['SKU-2', 10, null],
88  ];
89  }
90 
109  public function testReindexList(string $sku, int $stockId, $expectedData)
110  {
111  $this->sourceIndexer->executeList(['eu-1', 'us-1']);
112 
113  $stockItemData = $this->getStockItemData->execute($sku, $stockId);
114  self::assertEquals($expectedData, $stockItemData);
115  }
116 
134  public function testReindexAll(string $sku, int $stockId, $expectedData)
135  {
136  $this->sourceIndexer->executeFull();
137 
138  $stockItemData = $this->getStockItemData->execute($sku, $stockId);
139  self::assertEquals($expectedData, $stockItemData);
140  }
141 
145  public function reindexListDataProvider(): array
146  {
147  return [
149  ['SKU-1', 20, null],
151  ['SKU-2', 10, null],
155  ['SKU-3', 20, null],
157  ];
158  }
159 }