public function testExecuteWithIndex() { $this->configMock->expects($this->any())->method('getIndexer')->will($this->returnValueMap([['id_indexerOne', ['title' => 'Title_indexerOne', 'shared_index' => null]], ['id_indexerTwo', ['title' => 'Title_indexerTwo', 'shared_index' => 'with_indexer_3']], ['id_indexer3', ['title' => 'Title_indexer3', 'shared_index' => 'with_indexer_3']]])); $this->configureAdminArea(); $indexerOne = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false); $indexerOne->expects($this->once())->method('reindexAll'); $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); $indexerOne->expects($this->any())->method('getId')->willReturn('id_indexerOne'); $indexerOne->expects($this->once())->method('load')->with('id_indexerOne')->willReturn($indexerOne); $indexerTwo = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false); $indexerTwo->expects($this->once())->method('reindexAll'); $indexerTwo->expects($this->once())->method('getTitle')->willReturn('Title_indexerTwo'); $indexerTwo->expects($this->any())->method('getId')->willReturn('id_indexerTwo'); $indexerTwo->expects($this->once())->method('load')->with('id_indexerTwo')->willReturn($indexerTwo); $indexer3 = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false); $indexer3->expects($this->never())->method('reindexAll'); $indexer3->expects($this->once())->method('getTitle')->willReturn('Title_indexer3'); $indexer3->expects($this->any())->method('getId')->willReturn('id_indexer3'); $indexer3->expects($this->once())->method('load')->with('id_indexer3')->willReturn($indexer3); $stateMock = $this->getMock(\Magento\Indexer\Model\Indexer\State::class, [], [], '', false); $stateMock->expects($this->once())->method('setStatus')->will($this->returnSelf()); $stateMock->expects($this->once())->method('save'); $indexer3->expects($this->once())->method('getState')->willReturn($stateMock); $this->collectionFactory->expects($this->never())->method('create'); $this->indexerFactory->expects($this->at(0))->method('create')->willReturn($indexerOne); $this->indexerFactory->expects($this->at(1))->method('create')->willReturn($indexerTwo); $this->indexerFactory->expects($this->at(2))->method('create')->willReturn($indexer3); $this->command = new IndexerReindexCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); $commandTester->execute(['index' => ['id_indexerOne', 'id_indexerTwo', 'id_indexer3']]); $actualValue = $commandTester->getDisplay(); $this->assertStringStartsWith('Title_indexerOne index has been rebuilt successfully in', $actualValue); }
public function testReindexAllInvalid() { $indexers = ['indexer1' => [], 'indexer2' => []]; $this->configMock->expects($this->once())->method('getIndexers')->will($this->returnValue($indexers)); $state1Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer\\State', ['getStatus', '__wakeup'], [], '', false); $state1Mock->expects($this->once())->method('getStatus')->will($this->returnValue(StateInterface::STATUS_INVALID)); $indexer1Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer', ['load', 'getState', 'reindexAll'], [], '', false); $indexer1Mock->expects($this->once())->method('getState')->will($this->returnValue($state1Mock)); $indexer1Mock->expects($this->once())->method('reindexAll'); $state2Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer\\State', ['getStatus', '__wakeup'], [], '', false); $state2Mock->expects($this->once())->method('getStatus')->will($this->returnValue(StateInterface::STATUS_VALID)); $indexer2Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer', ['load', 'getState', 'reindexAll'], [], '', false); $indexer2Mock->expects($this->never())->method('reindexAll'); $indexer2Mock->expects($this->once())->method('getState')->will($this->returnValue($state2Mock)); $this->indexerFactoryMock->expects($this->at(0))->method('create')->will($this->returnValue($indexer1Mock)); $this->indexerFactoryMock->expects($this->at(1))->method('create')->will($this->returnValue($indexer2Mock)); $this->model->reindexAllInvalid(); }
/** * @param $indexId */ protected function loadIndexer($indexId) { $this->configMock->expects($this->once())->method('getIndexer')->with($indexId)->will($this->returnValue($this->getIndexerData())); $this->model->load($indexId); }