public function testGet() { $actionInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\ActionInterface', [], '', false); $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Mview\\ActionInterface')->will($this->returnValue($actionInterfaceMock)); $this->model->get('Magento\\Framework\\Mview\\ActionInterface'); $this->assertInstanceOf('Magento\\Framework\\Mview\\ActionInterface', $actionInterfaceMock); }
/** * Materialize view by IDs in changelog * * @return void * @throws \Exception */ public function update() { if ($this->getState()->getMode() == View\StateInterface::MODE_ENABLED && $this->getState()->getStatus() == View\StateInterface::STATUS_IDLE ) { $currentVersionId = $this->getChangelog()->getVersion(); $lastVersionId = $this->getState()->getVersionId(); $ids = $this->getChangelog()->getList($lastVersionId, $currentVersionId); if ($ids) { $action = $this->actionFactory->get($this->getActionClass()); $this->getState()->setStatus(View\StateInterface::STATUS_WORKING)->save(); try { $action->execute($ids); $this->getState()->loadByView($this->getId()); $statusToRestore = $this->getState()->getStatus() == View\StateInterface::STATUS_SUSPENDED ? View\StateInterface::STATUS_SUSPENDED : View\StateInterface::STATUS_IDLE; $this->getState()->setVersionId($currentVersionId)->setStatus($statusToRestore)->save(); } catch (\Exception $exception) { $this->getState()->loadByView($this->getId()); $statusToRestore = $this->getState()->getStatus() == View\StateInterface::STATUS_SUSPENDED ? View\StateInterface::STATUS_SUSPENDED : View\StateInterface::STATUS_IDLE; $this->getState()->setStatus($statusToRestore)->save(); throw $exception; } } } }
/** * @expectedException \Exception * @expectedExceptionMessage Test exception */ public function testUpdateWithException() { $currentVersionId = 3; $lastVersionId = 1; $listId = [2, 3]; $this->stateMock->expects($this->any())->method('getViewId')->will($this->returnValue(1)); $this->stateMock->expects($this->once())->method('getVersionId')->will($this->returnValue($lastVersionId)); $this->stateMock->expects($this->never())->method('setVersionId'); $this->stateMock->expects($this->exactly(2))->method('getStatus')->will($this->returnValue(\Magento\Framework\Mview\View\StateInterface::STATUS_IDLE)); $this->stateMock->expects($this->exactly(2))->method('setStatus')->will($this->returnSelf()); $this->stateMock->expects($this->exactly(2))->method('save')->will($this->returnSelf()); $this->changelogMock->expects($this->once())->method('getVersion')->will($this->returnValue($currentVersionId)); $this->changelogMock->expects($this->once())->method('getList')->with($lastVersionId, $currentVersionId)->will($this->returnValue($listId)); $actionMock = $this->getMock('Magento\\Framework\\Mview\\Action', ['execute'], [], '', false); $actionMock->expects($this->once())->method('execute')->with($listId)->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->loadView(); $this->model->update(); }