Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
EmailSenderTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Sales\Model\AdminOrder\EmailSender;
9 
10 class EmailSenderTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $orderMock;
16 
20  protected $loggerMock;
21 
26 
30  protected $emailSender;
31 
35  protected $orderSenderMock;
36 
40  protected function setUp()
41  {
42  $this->messageManagerMock = $this->createMock(\Magento\Framework\Message\Manager::class);
43  $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
44  $this->orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
45  $this->orderSenderMock = $this->createMock(\Magento\Sales\Model\Order\Email\Sender\OrderSender::class);
46 
47  $this->emailSender = new EmailSender($this->messageManagerMock, $this->loggerMock, $this->orderSenderMock);
48  }
49 
53  public function testSendSuccess()
54  {
55  $this->orderSenderMock->expects($this->once())
56  ->method('send');
57  $this->assertTrue($this->emailSender->send($this->orderMock));
58  }
59 
63  public function testSendFailure()
64  {
65  $this->orderSenderMock->expects($this->once())
66  ->method('send')
67  ->willThrowException(new \Magento\Framework\Exception\MailException(__('test message')));
68  $this->messageManagerMock->expects($this->once())
69  ->method('addWarningMessage');
70  $this->loggerMock->expects($this->once())
71  ->method('critical');
72 
73  $this->assertFalse($this->emailSender->send($this->orderMock));
74  }
75 }
__()
Definition: __.php:13