Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvalidateAfterEnablingOrDisablingSourceTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 use PHPUnit\Framework\TestCase;
16 
21 {
25  private $sourceRepository;
26 
30  private $indexer;
31 
32  protected function setUp()
33  {
34  $this->sourceRepository = Bootstrap::getObjectManager()->get(SourceRepositoryInterface::class);
36  $indexerRegistry = Bootstrap::getObjectManager()->get(IndexerRegistry::class);
37  $this->indexer = $indexerRegistry->get(InventoryIndexer::INDEXER_ID);
38  }
39 
57  public function testIndexerInvalidation(string $sourceCode, bool $enable, bool $expectedValid)
58  {
59  $this->setSourceEnabledStatus($sourceCode, $enable);
60 
61  $this->assertEquals($expectedValid, $this->indexer->isValid());
62  }
63 
67  public function indexerInvalidationDataProvider(): array
68  {
69  return [
70  ['eu-1', true, true],
71  ['eu-1', false, false],
72  ['eu-disabled', true, false],
73  ['eu-disabled', false, true],
74  ];
75  }
76 
89  string $sourceCode,
90  bool $enable,
91  bool $expectedValid
92  ) {
93  $this->setSourceEnabledStatus($sourceCode, $enable);
94 
95  $this->assertEquals($expectedValid, $this->indexer->isValid());
96  }
97 
112  string $sourceCode,
113  bool $enable,
114  bool $expectedValid
115  ) {
116  $this->setSourceEnabledStatus($sourceCode, $enable);
117 
118  $this->assertEquals($expectedValid, $this->indexer->isValid());
119  }
120 
137  string $sourceCode,
138  bool $enable,
139  bool $expectedValid
140  ) {
141  $this->setSourceEnabledStatus($sourceCode, $enable);
142 
143  $this->assertEquals($expectedValid, $this->indexer->isValid());
144  }
145 
150  {
151  return [
152  ['eu-1', true, true],
153  ['eu-1', false, true],
154  ['eu-disabled', true, true],
155  ['eu-disabled', false, true],
156  ];
157  }
158 
164  private function setSourceEnabledStatus(string $sourceCode, bool $enable)
165  {
166  $source = $this->sourceRepository->get($sourceCode);
167  $source->setEnabled($enable);
168  $this->sourceRepository->save($source);
169  }
170 }
$source
Definition: source.php:23
$sourceCode
Definition: inventory.phtml:11