Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InterpretationMediatorTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class InterpretationMediatorTest extends \PHPUnit\Framework\TestCase
13 {
17  private $interpretationStrategy;
18 
22  private $messageMock;
23 
27  private $interpretationMediator;
28 
29  protected function setUp()
30  {
31  $this->interpretationStrategy = $this->getMockBuilder(
32  \Magento\Framework\View\Element\Message\InterpretationStrategy::class
33  )
34  ->disableOriginalConstructor()
35  ->getMock();
36  $this->messageMock = $this->createMock(
37  \Magento\Framework\Message\MessageInterface::class
38  );
39 
40  $this->interpretationMediator = new InterpretationMediator(
41  $this->interpretationStrategy
42  );
43  }
44 
46  {
47  $messageText = 'Very awful message. Shame.';
48  $this->messageMock->expects(static::once())
49  ->method('getIdentifier')
50  ->willReturn(null);
51  $this->messageMock->expects(static::once())
52  ->method('getText')
53  ->willReturn($messageText);
54 
55  static::assertSame(
56  $messageText,
57  $this->interpretationMediator->interpret($this->messageMock)
58  );
59  }
60 
62  {
63  $messageInterpreted = 'Awesome message. An identified message is the one we appreciate.';
64 
65  $this->messageMock->expects(static::once())
66  ->method('getIdentifier')
67  ->willReturn('Great identifier');
68  $this->interpretationStrategy->expects(static::once())
69  ->method('interpret')
70  ->with($this->messageMock)
71  ->willReturn($messageInterpreted);
72 
73  static::assertSame(
74  $messageInterpreted,
75  $this->interpretationMediator->interpret($this->messageMock)
76  );
77  }
78 
80  {
81  $messageStillNotInterpreted = 'One step left to call it an awesome message.';
82 
83  $this->messageMock->expects(static::once())
84  ->method('getIdentifier')
85  ->willReturn('Great identifier');
86  $this->messageMock->expects(static::once())
87  ->method('getText')
88  ->willReturn($messageStillNotInterpreted);
89  $this->interpretationStrategy->expects(static::once())
90  ->method('interpret')
91  ->with($this->messageMock)
92  ->willThrowException(new \LogicException());
93 
94  static::assertSame(
95  $messageStillNotInterpreted,
96  $this->interpretationMediator->interpret($this->messageMock)
97  );
98  }
99 }