36 private $invoiceItemMock;
41 private $orderPaymentMock;
46 private $eventManagerMock;
51 private $paymentMethodMock;
58 $this->orderMock = $this->getMockForAbstractClass(
69 'setBaseTotalInvoiced',
70 'getBaseTotalInvoiced',
71 'setSubtotalInvoiced',
72 'getSubtotalInvoiced',
73 'setBaseSubtotalInvoiced',
74 'getBaseSubtotalInvoiced',
79 'setDiscountTaxCompensationInvoiced',
80 'getDiscountTaxCompensationInvoiced',
81 'setBaseDiscountTaxCompensationInvoiced',
82 'getBaseDiscountTaxCompensationInvoiced',
83 'setShippingTaxInvoiced',
84 'getShippingTaxInvoiced',
85 'setBaseShippingTaxInvoiced',
86 'getBaseShippingTaxInvoiced',
87 'setShippingInvoiced',
88 'getShippingInvoiced',
89 'setBaseShippingInvoiced',
90 'getBaseShippingInvoiced',
91 'setDiscountInvoiced',
92 'getDiscountInvoiced',
93 'setBaseDiscountInvoiced',
94 'getBaseDiscountInvoiced',
95 'setBaseTotalInvoicedCost',
96 'getBaseTotalInvoicedCost',
99 $this->orderMock->expects($this->any())
100 ->method(
'getTotalInvoiced')
102 $this->orderMock->expects($this->any())
103 ->method(
'getBaseTotalInvoiced')
105 $this->orderMock->expects($this->any())
106 ->method(
'getSubtotalInvoiced')
108 $this->orderMock->expects($this->any())
109 ->method(
'getBaseSubtotalInvoiced')
111 $this->orderMock->expects($this->any())
112 ->method(
'getTaxInvoiced')
114 $this->orderMock->expects($this->any())
115 ->method(
'getBaseTaxInvoiced')
117 $this->orderMock->expects($this->any())
118 ->method(
'getDiscountTaxCompensationInvoiced')
120 $this->orderMock->expects($this->any())
121 ->method(
'getBaseDiscountTaxCompensationInvoiced')
123 $this->orderMock->expects($this->any())
124 ->method(
'getShippingTaxInvoiced')
126 $this->orderMock->expects($this->any())
127 ->method(
'getBaseShippingTaxInvoiced')
129 $this->orderMock->expects($this->any())
130 ->method(
'getShippingInvoiced')
132 $this->orderMock->expects($this->any())
133 ->method(
'getBaseShippingInvoiced')
135 $this->orderMock->expects($this->any())
136 ->method(
'getDiscountInvoiced')
138 $this->orderMock->expects($this->any())
139 ->method(
'getBaseDiscountInvoiced')
141 $this->orderMock->expects($this->any())
142 ->method(
'getBaseTotalInvoicedCost')
145 $this->invoiceMock = $this->getMockForAbstractClass(
164 'getDiscountTaxCompensationAmount',
165 'getBaseDiscountTaxCompensationAmount',
166 'getShippingTaxAmount',
167 'getBaseShippingTaxAmount',
169 'getBaseShippingAmount',
171 'getBaseDiscountAmount',
175 $this->invoiceMock->expects($this->any())
176 ->method(
'getGrandTotal')
178 $this->invoiceMock->expects($this->any())
179 ->method(
'getBaseGrandTotal')
181 $this->invoiceMock->expects($this->any())
182 ->method(
'getSubtotal')
184 $this->invoiceMock->expects($this->any())
185 ->method(
'getBaseSubtotal')
187 $this->invoiceMock->expects($this->any())
188 ->method(
'getTaxAmount')
190 $this->invoiceMock->expects($this->any())
191 ->method(
'getBaseTaxAmount')
193 $this->invoiceMock->expects($this->any())
194 ->method(
'getDiscountTaxCompensationAmount')
196 $this->invoiceMock->expects($this->any())
197 ->method(
'getBaseDiscountTaxCompensationAmount')
199 $this->invoiceMock->expects($this->any())
200 ->method(
'getShippingTaxAmount')
202 $this->invoiceMock->expects($this->any())
203 ->method(
'getBaseShippingTaxAmount')
205 $this->invoiceMock->expects($this->any())
206 ->method(
'getShippingAmount')
208 $this->invoiceMock->expects($this->any())
209 ->method(
'getBaseShippingAmount')
211 $this->invoiceMock->expects($this->any())
212 ->method(
'getDiscountAmount')
214 $this->invoiceMock->expects($this->any())
215 ->method(
'getBaseDiscountAmount')
217 $this->invoiceMock->expects($this->any())
218 ->method(
'getBaseCost')
221 $this->contextMock = $this->createMock(\
Magento\Framework\Model\Context::class);
223 $this->invoiceItemMock = $this->getMockForAbstractClass(
224 \
Magento\Sales\Api\
Data\InvoiceItemInterface::class,
235 $this->invoiceItemMock->expects($this->any())
236 ->method(
'isDeleted')
238 $this->invoiceItemMock->expects($this->any())
242 $this->orderPaymentMock = $this->getMockForAbstractClass(
243 \
Magento\Sales\Api\
Data\OrderPaymentInterface::class,
252 'getIsTransactionPending',
255 $this->orderMock->expects($this->any())
256 ->method(
'getPayment')
257 ->willReturn($this->orderPaymentMock);
259 $this->eventManagerMock = $this->getMockForAbstractClass(
260 \
Magento\Framework\Event\ManagerInterface::class,
268 $this->contextMock->expects($this->any())
269 ->method(
'getEventDispatcher')
270 ->willReturn($this->eventManagerMock);
272 $this->paymentMethodMock = $this->getMockForAbstractClass(
281 $this->orderPaymentMock->expects($this->any())
282 ->method(
'getMethodInstance')
283 ->willReturn($this->paymentMethodMock);
285 $this->subject = new \Magento\Sales\Model\Order\Invoice\PayOperation(
301 public function testExecute($canCapture, $isOnline, $isGateway, $isTransactionPending)
303 $this->invoiceMock->expects($this->any())
305 ->willReturn([$this->invoiceItemMock]);
308 $this->invoiceMock->expects($this->any())
312 $this->orderPaymentMock->expects($this->any())
313 ->method(
'canCapture')
317 $this->invoiceMock->expects($this->once())
320 $this->invoiceMock->expects($this->never())
323 $this->invoiceMock->expects($this->once())
324 ->method(
'setCanVoidFlag')
327 $this->invoiceMock->expects($this->once())
331 $this->paymentMethodMock->expects($this->any())
332 ->method(
'isGateway')
333 ->willReturn($isGateway);
335 $this->orderPaymentMock->expects($this->any())
336 ->method(
'getIsTransactionPending')
337 ->willReturn($isTransactionPending);
339 $this->invoiceMock->expects($this->never())
342 if ((!$isGateway || !$isOnline) && !$isTransactionPending) {
343 $this->invoiceMock->expects($this->once())
344 ->method(
'setCanVoidFlag')
347 $this->invoiceMock->expects($this->once())
352 $this->orderMock->expects($this->once())
353 ->method(
'setTotalInvoiced')
355 $this->orderMock->expects($this->once())
356 ->method(
'setBaseTotalInvoiced')
358 $this->orderMock->expects($this->once())
359 ->method(
'setSubtotalInvoiced')
361 $this->orderMock->expects($this->once())
362 ->method(
'setBaseSubtotalInvoiced')
364 $this->orderMock->expects($this->once())
365 ->method(
'setTaxInvoiced')
367 $this->orderMock->expects($this->once())
368 ->method(
'setBaseTaxInvoiced')
370 $this->orderMock->expects($this->once())
371 ->method(
'setDiscountTaxCompensationInvoiced')
373 $this->orderMock->expects($this->once())
374 ->method(
'setBaseDiscountTaxCompensationInvoiced')
376 $this->orderMock->expects($this->once())
377 ->method(
'setShippingTaxInvoiced')
379 $this->orderMock->expects($this->once())
380 ->method(
'setBaseShippingTaxInvoiced')
382 $this->orderMock->expects($this->once())
383 ->method(
'setShippingInvoiced')
385 $this->orderMock->expects($this->once())
386 ->method(
'setBaseShippingInvoiced')
388 $this->orderMock->expects($this->once())
389 ->method(
'setDiscountInvoiced')
391 $this->orderMock->expects($this->once())
392 ->method(
'setBaseDiscountInvoiced')
394 $this->orderMock->expects($this->once())
395 ->method(
'setBaseTotalInvoicedCost')
398 $this->eventManagerMock->expects($this->once())
401 'sales_order_invoice_register',
403 'invoice' => $this->invoiceMock,
404 'order' => $this->orderMock,
410 $this->subject->execute(
424 'Invoice can capture, online' => [
425 true,
true,
null,
null,
427 'Invoice can capture, offline' => [
428 true,
false,
null,
null,
430 'Invoice can not capture, online, is not gateway, transaction is not pending' => [
431 false,
true,
false,
false,
433 'Invoice can not capture, offline, gateway, transaction is not pending' => [
434 false,
false,
true,
false,
testExecute($canCapture, $isOnline, $isGateway, $isTransactionPending)