public function setUp() { $this->_objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', array('getId', 'invalidate'), array(), '', false); $this->_indexerMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->_indexerFactoryMock = $this->getMock('Magento\\Indexer\\Model\\IndexerFactory', array('create'), array(), '', false); $this->_indexerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_indexerMock)); $this->_stateMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\State', array('isFlatEnabled'), array(), '', false); $this->_model = $this->_objectManager->getObject('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\Processor', array('indexerFactory' => $this->_indexerFactoryMock, 'state' => $this->_stateMock)); }
/** * @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()); }
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(Indexer\State::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(Indexer\State::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(); }