Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
RuleProductIndexerTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class RuleProductIndexerTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $indexBuilder;
17 
21  protected $indexer;
22 
26  protected $cacheContextMock;
27 
28  protected function setUp()
29  {
30  $this->indexBuilder = $this->createMock(\Magento\CatalogRule\Model\Indexer\IndexBuilder::class);
31 
32  $this->indexer = (new ObjectManager($this))->getObject(
33  \Magento\CatalogRule\Model\Indexer\Rule\RuleProductIndexer::class,
34  [
35  'indexBuilder' => $this->indexBuilder,
36  ]
37  );
38 
39  $this->cacheContextMock = $this->createMock(\Magento\Framework\Indexer\CacheContext::class);
40 
41  $cacheContextProperty = new \ReflectionProperty(
42  \Magento\CatalogRule\Model\Indexer\Rule\RuleProductIndexer::class,
43  'cacheContext'
44  );
45  $cacheContextProperty->setAccessible(true);
46  $cacheContextProperty->setValue($this->indexer, $this->cacheContextMock);
47  }
48 
49  public function testDoExecuteList()
50  {
51  $ids = [1, 2, 5];
52  $this->indexBuilder->expects($this->once())->method('reindexFull');
53  $this->cacheContextMock->expects($this->once())
54  ->method('registerTags')
55  ->with(
56  [
57  \Magento\Catalog\Model\Category::CACHE_TAG,
58  \Magento\Catalog\Model\Product::CACHE_TAG,
59  \Magento\Framework\App\Cache\Type\Block::CACHE_TAG
60  ]
61  );
62  $this->indexer->executeList($ids);
63  }
64 
65  public function testDoExecuteRow()
66  {
67  $this->indexBuilder->expects($this->once())->method('reindexFull');
68 
69  $this->indexer->executeRow(5);
70  }
71 }