public function testRemove() { $triggerMock = $this->getMock('Magento\\Framework\\DB\\Ddl\\Trigger', [], [], '', false, false); $triggerMock->expects($this->exactly(3))->method('setName')->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('triggerName')); $triggerMock->expects($this->exactly(3))->method('setTime')->with(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER)->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('setEvent')->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('setTable')->with($this->tableName)->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('addStatement')->will($this->returnSelf()); $this->triggerFactoryMock->expects($this->exactly(3))->method('create')->will($this->returnValue($triggerMock)); $otherChangelogMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\ChangelogInterface', [], '', false, false, true, []); $otherChangelogMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('other_test_view_cl')); $otherChangelogMock->expects($this->exactly(3))->method('getColumnName')->will($this->returnValue('entity_id')); $otherViewMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\ViewInterface', [], '', false, false, true, []); $otherViewMock->expects($this->exactly(1))->method('getId')->will($this->returnValue('other_id')); $otherViewMock->expects($this->exactly(1))->method('getSubscriptions')->will($this->returnValue([['name' => $this->tableName], ['name' => 'otherTableName']])); $otherViewMock->expects($this->exactly(3))->method('getChangelog')->will($this->returnValue($otherChangelogMock)); $this->viewMock->expects($this->exactly(3))->method('getId')->will($this->returnValue('this_id')); $this->viewMock->expects($this->never())->method('getSubscriptions'); $this->viewCollectionMock->expects($this->exactly(1))->method('getViewsByStateMode')->with(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED)->will($this->returnValue([$this->viewMock, $otherViewMock])); $this->connectionMock->expects($this->exactly(3))->method('dropTrigger')->with('triggerName')->will($this->returnValue(true)); $triggerMock->expects($this->exactly(3))->method('getStatements')->will($this->returnValue(true)); $this->connectionMock->expects($this->exactly(3))->method('createTrigger')->with($triggerMock); $this->model->remove(); }
/** * @param bool $scheduled * @param string $method * @dataProvider setScheduledDataProvider */ public function testSetScheduled($scheduled, $method) { $stateMock = $this->getMock('\\Magento\\Indexer\\Model\\Indexer\\State', ['load', 'save'], [], '', false); $this->stateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($stateMock)); $this->viewMock->expects($this->once())->method('load')->will($this->returnSelf()); $this->viewMock->expects($this->once())->method($method)->will($this->returnValue(true)); $stateMock->expects($this->once())->method('save')->will($this->returnSelf()); $this->model->setScheduled($scheduled); }
/** * @expectedException \Exception * @expectedExceptionMessage Test exception */ public function testReindexAllWithException() { $indexId = 'indexer_internal_name'; $this->loadIndexer($indexId); $stateMock = $this->getMock('\\Magento\\Indexer\\Model\\Indexer\\State', ['load', 'getId', 'setIndexerId', '__wakeup', 'getStatus', 'setStatus', 'save'], [], '', false); $stateMock->expects($this->once())->method('load')->with($indexId, 'indexer_id')->will($this->returnSelf()); $stateMock->expects($this->never())->method('setIndexerId'); $stateMock->expects($this->once())->method('getId')->will($this->returnValue(1)); $stateMock->expects($this->exactly(2))->method('setStatus')->will($this->returnSelf()); $stateMock->expects($this->once())->method('getStatus')->will($this->returnValue('idle')); $stateMock->expects($this->exactly(2))->method('save')->will($this->returnSelf()); $this->stateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($stateMock)); $this->viewMock->expects($this->once())->method('isEnabled')->will($this->returnValue(false)); $this->viewMock->expects($this->never())->method('suspend'); $this->viewMock->expects($this->once())->method('resume'); $actionMock = $this->getMock('Magento\\Indexer\\Model\\ActionInterface', ['executeFull', 'executeList', 'executeRow'], [], '', false); $actionMock->expects($this->once())->method('executeFull')->will($this->returnCallback(function () { throw new \Exception('Test exception'); })); $this->actionFactoryMock->expects($this->once())->method('get')->with('Some\\Class\\Name')->will($this->returnValue($actionMock)); $this->model->reindexAll(); }