Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractIndexerTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class AbstractIndexerTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $indexBuilder;
17 
21  protected $indexer;
22 
26  protected $_eventManagerMock;
27 
33  protected function setUp()
34  {
35  $this->_eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
36  $this->indexBuilder = $this->createMock(\Magento\CatalogRule\Model\Indexer\IndexBuilder::class);
37 
38  $this->indexer = $this->getMockForAbstractClass(
39  AbstractIndexer::class,
40  [
41  $this->indexBuilder,
42  $this->_eventManagerMock
43  ]
44  );
45  $cacheMock = $this->createMock(\Magento\Framework\App\CacheInterface::class);
46  $reflection = new \ReflectionClass(AbstractIndexer::class);
47  $reflectionProperty = $reflection->getProperty('cacheManager');
48  $reflectionProperty->setAccessible(true);
49  $reflectionProperty->setValue($this->indexer, $cacheMock);
50  }
51 
57  public function testExecute()
58  {
59  $ids = [1, 2, 5];
60  $this->indexer->expects($this->once())->method('doExecuteList')->with($ids);
61 
62  $this->indexer->execute($ids);
63  }
64 
70  public function testExecuteFull()
71  {
72  $this->indexBuilder->expects($this->once())->method('reindexFull');
73  $this->_eventManagerMock->expects($this->once())
74  ->method('dispatch')
75  ->with(
76  'clean_cache_by_tags',
77  ['object' => $this->indexer]
78  );
79 
80  $this->indexer->executeFull();
81  }
82 
89  public function testExecuteListWithEmptyIds()
90  {
91  $this->indexer->executeList([]);
92  }
93 
99  public function testExecuteList()
100  {
101  $ids = [1, 2, 5];
102  $this->indexer->expects($this->once())->method('doExecuteList')->with($ids);
103 
104  $this->indexer->executeList($ids);
105  }
106 
113  public function testExecuteRowWithEmptyId()
114  {
115  $this->indexer->executeRow(null);
116  }
117 
123  public function testExecuteRow()
124  {
125  $id = 5;
126  $this->indexer->expects($this->once())->method('doExecuteRow')->with($id);
127 
128  $this->indexer->executeRow($id);
129  }
130 }
$id
Definition: fieldset.phtml:14