Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractSenderTest.php
Go to the documentation of this file.
1 <?php
7 
13 abstract class AbstractSenderTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $senderMock;
19 
24 
29 
34 
38  protected $storeMock;
39 
43  protected $orderMock;
44 
48  protected $paymentHelper;
49 
53  protected $addressRenderer;
54 
60  protected $globalConfig;
61 
65  protected $addressMock;
66 
70  protected $eventManagerMock;
71 
75  protected $loggerMock;
76 
77  public function stepMockSetup()
78  {
79  $this->senderMock = $this->createPartialMock(
80  \Magento\Sales\Model\Order\Email\Sender::class,
81  ['send', 'sendCopyTo']
82  );
83 
84  $this->senderBuilderFactoryMock = $this->createPartialMock(
85  \Magento\Sales\Model\Order\Email\SenderBuilderFactory::class,
86  ['create']
87  );
88  $this->templateContainerMock = $this->createPartialMock(
89  \Magento\Sales\Model\Order\Email\Container\Template::class,
90  ['setTemplateVars']
91  );
92 
93  $this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getStoreId', '__wakeup']);
94 
95  $this->orderMock = $this->createPartialMock(\Magento\Sales\Model\Order::class, [
96  'getStore', 'getBillingAddress', 'getPayment',
97  '__wakeup', 'getCustomerIsGuest', 'getCustomerName',
98  'getCustomerEmail', 'getShippingAddress', 'setSendEmail',
99  'setEmailSent'
100  ]);
101  $this->orderMock->expects($this->any())
102  ->method('getStore')
103  ->will($this->returnValue($this->storeMock));
104  $paymentInfoMock = $this->createMock(\Magento\Payment\Model\Info::class);
105  $this->orderMock->expects($this->any())
106  ->method('getPayment')
107  ->will($this->returnValue($paymentInfoMock));
108 
109  $this->addressRenderer = $this->createMock(\Magento\Sales\Model\Order\Address\Renderer::class);
110  $this->addressMock = $this->createMock(\Magento\Sales\Model\Order\Address::class);
111  $this->eventManagerMock = $this->createMock(\Magento\Framework\Event\Manager::class);
112 
113  $this->paymentHelper = $this->createPartialMock(\Magento\Payment\Helper\Data::class, ['getInfoBlockHtml']);
114  $this->paymentHelper->expects($this->any())
115  ->method('getInfoBlockHtml')
116  ->will($this->returnValue('payment'));
117 
118  $this->globalConfig = $this->createPartialMock(\Magento\Framework\App\Config::class, ['getValue']);
119 
120  $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
121  }
122 
127  public function stepAddressFormat($billingAddress, $isVirtual = false)
128  {
129  $this->orderMock->expects($this->any())
130  ->method('getBillingAddress')
131  ->will($this->returnValue($billingAddress));
132  if ($isVirtual) {
133  $this->orderMock->expects($this->never())
134  ->method('getShippingAddress');
135  } else {
136  $this->orderMock->expects($this->once())
137  ->method('getShippingAddress')
138  ->will($this->returnValue($billingAddress));
139  }
140  }
141 
142  public function stepSendWithoutSendCopy()
143  {
144  $this->stepSend($this->once(), $this->never());
145  }
146 
147  public function stepSendWithCallSendCopyTo()
148  {
149  $this->stepSend($this->never(), $this->once());
150  }
151 
155  public function stepIdentityContainerInit($identityMockClassName)
156  {
157  $this->identityContainerMock = $this->createPartialMock(
158  $identityMockClassName,
159  ['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId']
160  );
161  $this->identityContainerMock->expects($this->any())
162  ->method('getStore')
163  ->will($this->returnValue($this->storeMock));
164  }
165 
170  protected function stepSend(
171  \PHPUnit\Framework\MockObject\Matcher\InvokedCount $sendExpects,
172  \PHPUnit\Framework\MockObject\Matcher\InvokedCount $sendCopyToExpects
173  ) {
174  $senderMock = $this->createPartialMock(\Magento\Sales\Model\Order\Email\Sender::class, ['send', 'sendCopyTo']);
175  $senderMock->expects($sendExpects)
176  ->method('send');
177  $senderMock->expects($sendCopyToExpects)
178  ->method('sendCopyTo');
179 
180  $this->senderBuilderFactoryMock->expects($this->once())
181  ->method('create')
182  ->will($this->returnValue($senderMock));
183  }
184 }
$billingAddress
Definition: order.php:25
stepSend(\PHPUnit\Framework\MockObject\Matcher\InvokedCount $sendExpects, \PHPUnit\Framework\MockObject\Matcher\InvokedCount $sendCopyToExpects)