6 declare(strict_types=1);
12 use Magento\Sales\Api\Data\ShipmentCommentInterfaceFactory;
13 use Magento\Sales\Api\Data\ShipmentCommentSearchResultInterfaceFactory;
19 use Psr\Log\LoggerInterface;
31 private $commentResource;
36 private $commentFactory;
41 private $searchResultFactory;
46 private $collectionProcessor;
51 private $commentRepository;
56 private $shipmentCommentSender;
61 private $shipmentRepositoryMock;
66 private $shipmentMock;
80 $this->commentResource = $this->getMockBuilder(ShipmentCommentResourceInterface::class)
81 ->disableOriginalConstructor()
83 $this->commentFactory = $this->getMockBuilder(ShipmentCommentInterfaceFactory::class)
84 ->disableOriginalConstructor()
86 $this->searchResultFactory = $this->getMockBuilder(ShipmentCommentSearchResultInterfaceFactory::class)
87 ->disableOriginalConstructor()
89 $this->collectionProcessor = $this->getMockBuilder(CollectionProcessorInterface::class)
90 ->disableOriginalConstructor()
92 $this->shipmentRepositoryMock = $this->getMockBuilder(ShipmentRepositoryInterface::class)
93 ->disableOriginalConstructor()
95 $this->shipmentCommentSender = $this->getMockBuilder(ShipmentCommentSender::class)
96 ->disableOriginalConstructor()
98 $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
100 $this->shipmentMock = $this->getMockBuilder(Shipment::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->shipmentCommentSender,
109 $this->shipmentRepositoryMock,
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($shipmentId);
128 $this->commentMock->expects($this->once())
129 ->method(
'getComment')
130 ->willReturn($comment);
132 $this->shipmentRepositoryMock->expects($this->once())
135 ->willReturn($this->shipmentMock);
136 $this->shipmentCommentSender->expects($this->once())
138 ->with($this->shipmentMock,
true, $comment);
139 $this->assertEquals($this->commentMock, $this->commentRepository->save($this->commentMock));
148 $this->commentResource->expects($this->once())
150 ->with($this->commentMock)
151 ->willThrowException(
155 $this->commentRepository->save($this->commentMock);
160 $comment =
"Comment text";
162 $this->commentResource->expects($this->once())
164 ->with($this->commentMock)
166 $this->commentMock->expects($this->once())
167 ->method(
'getIsCustomerNotified')
169 $this->commentMock->expects($this->once())
170 ->method(
'getParentId')
171 ->willReturn($creditmemoId);
172 $this->commentMock->expects($this->once())
173 ->method(
'getComment')
174 ->willReturn($comment);
176 $this->shipmentRepositoryMock->expects($this->once())
178 ->with($creditmemoId)
179 ->willReturn($this->shipmentMock);
180 $this->shipmentCommentSender->expects($this->once())
182 ->willThrowException(
new \Exception());
183 $this->loggerMock->expects($this->once())
184 ->method(
'critical');
186 $this->commentRepository->save($this->commentMock);