messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)->getMock(); $this->messageInterpretationStrategy = $this->createMock( \Magento\Framework\View\Element\Message\InterpretationStrategyInterface::class ); $this->object = new Messages($this->messageManager, $this->messageInterpretationStrategy); } public function testGetSectionData() { $msgType = 'error'; $msgText = 'All is lost'; $msg = $this->getMockBuilder(\Magento\Framework\Message\MessageInterface::class)->getMock(); $messages = [$msg]; $msgCollection = $this->getMockBuilder(\Magento\Framework\Message\Collection::class) ->getMock(); $msg->expects($this->once()) ->method('getType') ->willReturn($msgType); $this->messageInterpretationStrategy->expects(static::once()) ->method('interpret') ->with($msg) ->willReturn($msgText); $this->messageManager->expects($this->once()) ->method('getMessages') ->with(true, null) ->willReturn($msgCollection); $msgCollection->expects($this->once()) ->method('getItems') ->willReturn($messages); $this->assertEquals( ['messages' => [['type' => $msgType, 'text' => $msgText]]], $this->object->getSectionData() ); } }