Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MessagesTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class MessagesTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $messageManager;
17 
21  private $messageInterpretationStrategy;
22 
26  protected $object;
27 
28  protected function setUp()
29  {
30  $this->messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)->getMock();
31  $this->messageInterpretationStrategy = $this->createMock(
32  \Magento\Framework\View\Element\Message\InterpretationStrategyInterface::class
33  );
34  $this->object = new Messages($this->messageManager, $this->messageInterpretationStrategy);
35  }
36 
37  public function testGetSectionData()
38  {
39  $msgType = 'error';
40  $msgText = 'All is lost';
41  $msg = $this->getMockBuilder(\Magento\Framework\Message\MessageInterface::class)->getMock();
42  $messages = [$msg];
43  $msgCollection = $this->getMockBuilder(\Magento\Framework\Message\Collection::class)
44  ->getMock();
45 
46  $msg->expects($this->once())
47  ->method('getType')
48  ->willReturn($msgType);
49  $this->messageInterpretationStrategy->expects(static::once())
50  ->method('interpret')
51  ->with($msg)
52  ->willReturn($msgText);
53  $this->messageManager->expects($this->once())
54  ->method('getMessages')
55  ->with(true, null)
56  ->willReturn($msgCollection);
57  $msgCollection->expects($this->once())
58  ->method('getItems')
59  ->willReturn($messages);
60 
61  $this->assertEquals(
62  ['messages' => [['type' => $msgType, 'text' => $msgText]]],
63  $this->object->getSectionData()
64  );
65  }
66 }