23 private $orderPaymentRepositoryMock;
28 private $orderRepositoryMock;
42 $this->invoiceMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\Invoice::class)
43 ->disableOriginalConstructor()
45 $this->orderPaymentRepositoryMock = $this->getMockBuilder(
46 \
Magento\Sales\Api\OrderPaymentRepositoryInterface::class
48 ->disableOriginalConstructor()
49 ->getMockForAbstractClass();
50 $this->orderRepositoryMock = $this->getMockBuilder(\
Magento\Sales\Api\OrderRepositoryInterface::class)
51 ->disableOriginalConstructor()
52 ->getMockForAbstractClass();
53 $this->paymentMock = $this->getMockBuilder(\
Magento\
Payment\Model\InfoInterface::class)
54 ->disableOriginalConstructor()
55 ->getMockForAbstractClass();
56 $this->validator = new \Magento\Sales\Model\Order\Invoice\Validation\CanRefund(
57 $this->orderPaymentRepositoryMock,
58 $this->orderRepositoryMock
64 $this->invoiceMock->expects($this->exactly(2))
66 ->willReturnOnConsecutiveCalls(
71 [
__(
'We can\'t create creditmemo for the invoice.')],
72 $this->validator->validate($this->invoiceMock)
75 [
__(
'We can\'t create creditmemo for the invoice.')],
76 $this->validator->validate($this->invoiceMock)
82 $this->invoiceMock->expects($this->once())
85 $this->invoiceMock->expects($this->once())
86 ->method(
'getBaseGrandTotal')
88 $this->invoiceMock->expects($this->once())
89 ->method(
'getBaseTotalRefunded')
92 [
__(
'We can\'t create creditmemo for the invoice.')],
93 $this->validator->validate($this->invoiceMock)
99 $this->invoiceMock->expects($this->once())
102 $orderMock = $this->getMockBuilder(OrderInterface::class)
103 ->disableOriginalConstructor()
104 ->getMockForAbstractClass();
105 $this->orderRepositoryMock->expects($this->once())
107 ->willReturn($orderMock);
108 $orderMock->expects($this->once())
109 ->method(
'getPayment')
110 ->willReturn($this->paymentMock);
111 $methodInstanceMock = $this->getMockBuilder(\
Magento\
Payment\Model\MethodInterface::class)
112 ->disableOriginalConstructor()
113 ->getMockForAbstractClass();
114 $this->paymentMock->expects($this->once())
115 ->method(
'getMethodInstance')
116 ->willReturn($methodInstanceMock);
117 $methodInstanceMock->expects($this->atLeastOnce())
118 ->method(
'canRefund')
120 $this->invoiceMock->expects($this->once())
121 ->method(
'getBaseGrandTotal')
123 $this->invoiceMock->expects($this->once())
124 ->method(
'getBaseTotalRefunded')
128 $this->validator->validate($this->invoiceMock)
testValidateInvoiceSumWasRefunded()
testValidateWrongInvoiceState()