/** * Regenerate indexes for all indexers * * @return void */ public function reindexAll() { /** @var IndexerInterface[] $indexers */ $indexers = $this->indexersFactory->create()->getItems(); foreach ($indexers as $indexer) { $indexer->reindexAll(); } }
public function testReindexAll() { $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false); $indexerMock->expects($this->exactly(2))->method('reindexAll'); $indexers = [$indexerMock, $indexerMock]; $indexersMock = $this->getMock('Magento\\Indexer\\Model\\Indexer\\Collection', [], [], '', false); $this->indexersFactoryMock->expects($this->once())->method('create')->will($this->returnValue($indexersMock)); $indexersMock->expects($this->once())->method('getItems')->will($this->returnValue($indexers)); $this->model->reindexAll(); }
/** * @param string $args * @dataProvider runExceptionDataProvider */ public function testRunException($args) { $indexerMock = $this->getMock('\\Magento\\Indexer\\Model\\Indexer', ['reindexAll', 'turnViewOff', 'turnViewOn'], [], '', false); $this->model->setRawArgs(['testme.php', '--', $args]); if ($args == 'reindex') { $indexerMock->expects($this->any())->method('reindexAll')->will($this->throwException(new \Exception())); } if ($args == '--mode-realtime') { $indexerMock->expects($this->any())->method('turnViewOff')->will($this->throwException(new \Exception())); } if ($args == 'reindexall') { $indexerMock->expects($this->any())->method('reindexAll')->will($this->throwException(new \Magento\Framework\Exception\LocalizedException(__('Something went wrong during reindexing all.')))); } if ($args == '--mode-schedule') { $indexerMock->expects($this->any())->method('turnViewOn')->will($this->throwException(new \Magento\Framework\Exception\LocalizedException(__('Something went wrong during turning view on.')))); } if ($args == '--reindex=price') { $this->indexerFactoryMock->expects($this->once())->method('create')->will($this->returnSelf()); $this->indexerFactoryMock->expects($this->any())->method('load')->will($this->throwException(new \Exception())); } else { $this->indexersFactoryMock->expects($this->once())->method('create')->will($this->returnSelf()); $this->indexersFactoryMock->expects($this->once())->method('getItems')->will($this->returnValue([$indexerMock])); } ob_start(); $this->assertInstanceOf('\\Magento\\Indexer\\Model\\Shell', $this->model->run()); ob_end_clean(); $this->assertEquals(true, $this->model->hasErrors()); }
/** * Returns all indexers * * @return IndexerInterface[] */ protected function getAllIndexers() { /** @var Indexer[] $indexers */ return $this->collectionFactory->create()->getItems(); }
/** * Perform full reindex */ private function reindex() { foreach ($this->indexerCollectionFactory->create()->getItems() as $indexer) { $indexer->reindexAll(); } }