public function testSaveActionThrowsException() { $this->requestMock->expects($this->any())->method('getPostValue')->willReturn(true); $this->requestMock->expects($this->atLeastOnce())->method('getParam')->willReturnMap([['block_id', null, 1], ['back', null, true]]); $this->objectManagerMock->expects($this->atLeastOnce())->method('create')->with($this->equalTo('Magento\\Cms\\Model\\Block'))->willReturn($this->blockMock); $this->objectManagerMock->expects($this->atLeastOnce())->method('get')->willReturnMap([['Magento\\Backend\\Model\\Session', $this->sessionMock]]); $this->blockMock->expects($this->any())->method('load')->willReturnSelf(); $this->blockMock->expects($this->any())->method('getId')->willReturn(true); $this->blockMock->expects($this->once())->method('setData'); $this->blockMock->expects($this->once())->method('save')->willThrowException(new \Exception('Error message.')); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with(__('You saved the block.')); $this->messageManagerMock->expects($this->once())->method('addError'); $this->sessionMock->expects($this->atLeastOnce())->method('setFormData')->with(true); $this->resultRedirect->expects($this->atLeastOnce())->method('setPath')->with('*/*/edit', ['block_id' => $this->blockId])->willReturnSelf(); $this->assertSame($this->resultRedirect, $this->saveController->executeInternal()); }