Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UrlRewriteExceptionMessageFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class UrlRewriteExceptionMessageFactoryTest extends \PHPUnit\Framework\TestCase
13 {
17  private $messageFactoryMock;
18 
22  private $urlMock;
23 
27  private $urlRewriteExceptionMessageFactory;
28 
29  protected function setUp()
30  {
31  $this->urlMock = $this->createMock(\Magento\Framework\UrlInterface::class);
32 
33  $this->messageFactoryMock = $this->createPartialMock(
34  \Magento\Framework\Message\Factory::class,
35  ['create']
36  );
37 
38  $this->urlRewriteExceptionMessageFactory = new UrlRewriteExceptionMessageFactory(
39  $this->messageFactoryMock,
40  $this->urlMock
41  );
42  }
43 
44  public function testCreateMessage()
45  {
46  $exception = new \Exception('exception');
47  $urlAlreadyExistsException = new UrlAlreadyExistsException(
48  __('message'),
49  $exception,
50  0,
51  [['request_path' => 'url']]
52  );
53 
54  $this->urlMock->expects($this->once())
55  ->method('getUrl')
56  ->willReturn('htmlUrl');
57 
58  $message = $this->createMock(MessageInterface::class);
59 
60  $message->expects($this->once())
61  ->method('setText')
62  ->with($urlAlreadyExistsException->getMessage())
63  ->willReturn($message);
64 
65  $message->expects($this->once())
66  ->method('setIdentifier')
68  ->willReturnSelf();
69 
70  $message->expects($this->once())
71  ->method('setData')
72  ->with(['urls' => ['htmlUrl' => 'url']])
73  ->willReturn($message);
74 
75  $this->messageFactoryMock->expects($this->once())
76  ->method('create')
78  ->willReturn($message);
79 
80  $this->assertEquals(
81  $message,
82  $this->urlRewriteExceptionMessageFactory->createMessage($urlAlreadyExistsException)
83  );
84  }
85 
89  public function testCreateMessageNotFound()
90  {
91  $exception = new \Exception('message');
92  $this->urlRewriteExceptionMessageFactory->createMessage($exception);
93  }
94 }
__()
Definition: __.php:13
$message