6 declare(strict_types=1);
12 use Magento\Sales\Api\Data\InvoiceCommentInterfaceFactory;
13 use Magento\Sales\Api\Data\InvoiceCommentSearchResultInterfaceFactory;
19 use Psr\Log\LoggerInterface;
31 private $commentResource;
36 private $commentFactory;
41 private $searchResultFactory;
46 private $collectionProcessor;
51 private $commentRepository;
56 private $invoiceCommentSender;
61 private $invoiceRepositoryMock;
80 $this->commentResource = $this->getMockBuilder(InvoiceCommentResourceInterface::class)
81 ->disableOriginalConstructor()
83 $this->commentFactory = $this->getMockBuilder(InvoiceCommentInterfaceFactory::class)
84 ->disableOriginalConstructor()
86 $this->searchResultFactory = $this->getMockBuilder(InvoiceCommentSearchResultInterfaceFactory::class)
87 ->disableOriginalConstructor()
89 $this->collectionProcessor = $this->getMockBuilder(CollectionProcessorInterface::class)
90 ->disableOriginalConstructor()
92 $this->invoiceRepositoryMock = $this->getMockBuilder(InvoiceRepositoryInterface::class)
93 ->disableOriginalConstructor()
95 $this->invoiceCommentSender = $this->getMockBuilder(InvoiceCommentSender::class)
96 ->disableOriginalConstructor()
98 $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
100 $this->invoiceMock = $this->getMockBuilder(Invoice::class)->disableOriginalConstructor()->getMock();
101 $this->commentMock = $this->getMockBuilder(Comment::class)->disableOriginalConstructor()->getMock();
104 $this->commentResource,
105 $this->commentFactory,
106 $this->searchResultFactory,
107 $this->collectionProcessor,
108 $this->invoiceCommentSender,
109 $this->invoiceRepositoryMock,
116 $comment =
"Comment text";
118 $this->commentResource->expects($this->once())
120 ->with($this->commentMock)
122 $this->commentMock->expects($this->once())
123 ->method(
'getIsCustomerNotified')
125 $this->commentMock->expects($this->once())
126 ->method(
'getParentId')
127 ->willReturn($invoiceId);
128 $this->commentMock->expects($this->once())
129 ->method(
'getComment')
130 ->willReturn($comment);
132 $this->invoiceRepositoryMock->expects($this->once())
135 ->willReturn($this->invoiceMock);
136 $this->invoiceCommentSender->expects($this->once())
138 ->with($this->invoiceMock,
true, $comment)
140 $this->commentRepository->save($this->commentMock);
149 $this->commentResource->expects($this->once())
151 ->with($this->commentMock)
152 ->willThrowException(
156 $this->commentRepository->save($this->commentMock);
161 $comment =
"Comment text";
163 $this->commentResource->expects($this->once())
165 ->with($this->commentMock)
167 $this->commentMock->expects($this->once())
168 ->method(
'getIsCustomerNotified')
170 $this->commentMock->expects($this->once())
171 ->method(
'getParentId')
172 ->willReturn($creditmemoId);
173 $this->commentMock->expects($this->once())
174 ->method(
'getComment')
175 ->willReturn($comment);
177 $this->invoiceRepositoryMock->expects($this->once())
179 ->with($creditmemoId)
180 ->willReturn($this->invoiceMock);
181 $this->invoiceCommentSender->expects($this->once())
183 ->willThrowException(
new \Exception());
184 $this->loggerMock->expects($this->once())
185 ->method(
'critical');
187 $this->commentRepository->save($this->commentMock);