Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\Indexer\IndexerInterfaceFactory;
10 
11 class ProcessorTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $model;
17 
21  protected $configMock;
22 
27 
32 
36  protected $viewProcessorMock;
37 
38  protected function setUp()
39  {
40  $this->configMock = $this->getMockForAbstractClass(
41  \Magento\Framework\Indexer\ConfigInterface::class,
42  [],
43  '',
44  false,
45  false,
46  true,
47  ['getIndexers']
48  );
49  $this->indexerFactoryMock = $this->createPartialMock(
50  IndexerInterfaceFactory::class,
51  ['create']
52  );
53  $this->indexersFactoryMock = $this->createPartialMock(
54  \Magento\Indexer\Model\Indexer\CollectionFactory::class,
55  ['create']
56  );
57  $this->viewProcessorMock = $this->getMockForAbstractClass(
58  \Magento\Framework\Mview\ProcessorInterface::class,
59  [],
60  '',
61  false
62  );
63  $this->model = new \Magento\Indexer\Model\Processor(
64  $this->configMock,
65  $this->indexerFactoryMock,
66  $this->indexersFactoryMock,
67  $this->viewProcessorMock
68  );
69  }
70 
71  public function testReindexAllInvalid()
72  {
73  $indexers = ['indexer1' => [], 'indexer2' => []];
74 
75  $this->configMock->expects($this->once())->method('getIndexers')->will($this->returnValue($indexers));
76 
77  $state1Mock = $this->createPartialMock(\Magento\Indexer\Model\Indexer\State::class, ['getStatus', '__wakeup']);
78  $state1Mock->expects(
79  $this->once()
80  )->method(
81  'getStatus'
82  )->will(
83  $this->returnValue(StateInterface::STATUS_INVALID)
84  );
85  $indexer1Mock = $this->createPartialMock(
86  \Magento\Indexer\Model\Indexer::class,
87  ['load', 'getState', 'reindexAll']
88  );
89  $indexer1Mock->expects($this->once())->method('getState')->will($this->returnValue($state1Mock));
90  $indexer1Mock->expects($this->once())->method('reindexAll');
91 
92  $state2Mock = $this->createPartialMock(\Magento\Indexer\Model\Indexer\State::class, ['getStatus', '__wakeup']);
93  $state2Mock->expects(
94  $this->once()
95  )->method(
96  'getStatus'
97  )->will(
98  $this->returnValue(StateInterface::STATUS_VALID)
99  );
100  $indexer2Mock = $this->createPartialMock(
101  \Magento\Indexer\Model\Indexer::class,
102  ['load', 'getState', 'reindexAll']
103  );
104  $indexer2Mock->expects($this->never())->method('reindexAll');
105  $indexer2Mock->expects($this->once())->method('getState')->will($this->returnValue($state2Mock));
106 
107  $this->indexerFactoryMock->expects($this->at(0))->method('create')->will($this->returnValue($indexer1Mock));
108  $this->indexerFactoryMock->expects($this->at(1))->method('create')->will($this->returnValue($indexer2Mock));
109 
110  $this->model->reindexAllInvalid();
111  }
112 
113  public function testReindexAll()
114  {
115  $indexerMock = $this->createMock(\Magento\Indexer\Model\Indexer::class);
116  $indexerMock->expects($this->exactly(2))->method('reindexAll');
117  $indexers = [$indexerMock, $indexerMock];
118 
119  $indexersMock = $this->createMock(\Magento\Indexer\Model\Indexer\Collection::class);
120  $this->indexersFactoryMock->expects($this->once())->method('create')->will($this->returnValue($indexersMock));
121  $indexersMock->expects($this->once())->method('getItems')->will($this->returnValue($indexers));
122 
123  $this->model->reindexAll();
124  }
125 
126  public function testUpdateMview()
127  {
128  $this->viewProcessorMock->expects($this->once())->method('update')->with('indexer')->willReturnSelf();
129  $this->model->updateMview();
130  }
131 
132  public function testClearChangelog()
133  {
134  $this->viewProcessorMock->expects($this->once())->method('clearChangelog')->with('indexer')->willReturnSelf();
135  $this->model->clearChangelog();
136  }
137 }