/** * @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 result of running model - can be real model or mocked one * * @param \Magento\Indexer\Model\Shell $model Can be mock * @return string */ protected function runModel($model) { ob_start(); $model->run(); $result = ob_get_contents(); ob_end_clean(); return $result; }