Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExceptionMessageFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class ExceptionMessageFactoryTest extends \PHPUnit\Framework\TestCase
12 {
16  private $messageFactoryMock;
17 
21  private $exceptionMessageFactory;
22 
23  protected function setUp()
24  {
25  $this->messageFactoryMock = $this->createPartialMock(
26  \Magento\Framework\Message\Factory::class,
27  ['create']
28  );
29 
30  $this->exceptionMessageFactory = new \Magento\Framework\Message\ExceptionMessageFactory(
31  $this->messageFactoryMock
32  );
33  }
34 
35  public function testCreateMessageDefaultType()
36  {
37  $exception = new \Exception('message');
38  $message = $this->createMock(MessageInterface::class);
39 
40  $message->expects($this->once())
41  ->method('setText')
42  ->with($exception->getMessage())
43  ->willReturn($message);
44 
45  $this->messageFactoryMock->expects($this->once())
46  ->method('create')
48  ->willReturn($message);
49 
50  $this->assertEquals(
51  $message,
52  $this->exceptionMessageFactory->createMessage($exception)
53  );
54  }
55 }
$message