Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductRuleIndexerTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ProductRuleIndexerTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $indexBuilder;
16 
20  protected $indexer;
21 
25  protected $cacheContextMock;
26 
27  protected function setUp()
28  {
29  $this->indexBuilder = $this->createMock(\Magento\CatalogRule\Model\Indexer\IndexBuilder::class);
30 
31  $this->indexer = (new ObjectManager($this))->getObject(
32  \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer::class,
33  [
34  'indexBuilder' => $this->indexBuilder,
35  ]
36  );
37 
38  $this->cacheContextMock = $this->createMock(\Magento\Framework\Indexer\CacheContext::class);
39 
40  $cacheContextProperty = new \ReflectionProperty(
41  \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer::class,
42  'cacheContext'
43  );
44  $cacheContextProperty->setAccessible(true);
45  $cacheContextProperty->setValue($this->indexer, $this->cacheContextMock);
46  }
47 
53  public function testDoExecuteList($ids, $idsForIndexer)
54  {
55  $this->indexBuilder->expects($this->once())
56  ->method('reindexByIds')
57  ->with($idsForIndexer);
58  $this->cacheContextMock->expects($this->once())
59  ->method('registerEntities')
60  ->with(\Magento\Catalog\Model\Product::CACHE_TAG, $ids);
61  $this->indexer->executeList($ids);
62  }
63 
67  public function dataProviderForExecuteList()
68  {
69  return [
70  [
71  [1, 2, 3, 2, 3],
72  [1, 2, 3],
73  ],
74  [
75  [1, 2, 3],
76  [1, 2, 3],
77  ],
78  ];
79  }
80 
81  public function testDoExecuteRow()
82  {
83  $id = 5;
84  $this->indexBuilder->expects($this->once())->method('reindexById')->with($id);
85 
86  $this->indexer->executeRow($id);
87  }
88 }
$id
Definition: fieldset.phtml:14