9 use Magento\Sales\Api\Data\CreditmemoCommentInterfaceFactory;
32 private $objectManager;
42 private $creditmemoFactoryMock;
47 private $commentFactoryMock;
52 private $hydratorPoolMock;
57 private $hydratorMock;
72 private $creditmemoItemCreationMock;
77 private $commentCreationMock;
82 private $commentCreationArgumentsMock;
87 private $creditmemoMock;
97 private $orderRepositoryMock;
102 $this->creditmemoFactoryMock = $this->getMockBuilder(CreditmemoFactory::class)
103 ->disableOriginalConstructor()
105 $this->commentFactoryMock =
106 $this->getMockBuilder(CreditmemoCommentInterfaceFactory::class)
107 ->disableOriginalConstructor()
109 $this->hydratorPoolMock = $this->getMockBuilder(HydratorPool::class)
110 ->disableOriginalConstructor()
112 $this->orderRepositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class)
113 ->disableOriginalConstructor()
115 $this->orderMock = $this->getMockBuilder(Order::class)
116 ->disableOriginalConstructor()
118 $this->invoiceMock = $this->getMockBuilder(Invoice::class)
119 ->disableOriginalConstructor()
121 $this->creditmemoItemCreationMock = $this->getMockBuilder(CreditmemoItemCreationInterface::class)
122 ->disableOriginalConstructor()
124 $this->creditmemoMock = $this->getMockBuilder(CreditmemoInterface::class)
125 ->disableOriginalConstructor()
127 $this->hydratorMock = $this->getMockBuilder(HydratorInterface::class)
128 ->disableOriginalConstructor()
130 $this->commentCreationArgumentsMock = $this->getMockBuilder(CreditmemoCreationArgumentsInterface::class)
131 ->disableOriginalConstructor()
133 $this->commentCreationMock = $this->getMockBuilder(CreditmemoCommentCreationInterface::class)
134 ->disableOriginalConstructor()
136 $this->creditmemoMock->expects($this->once())
137 ->method(
'getEntityId')
140 $this->commentMock = $this->getMockBuilder(CreditmemoCommentInterface::class)
141 ->disableOriginalConstructor()
144 get_class_methods(CreditmemoCommentInterface::class),
145 [
'setStoreId',
'setCreditmemo']
149 $this->factory = $this->objectManager->getObject(
150 CreditmemoDocumentFactory::class,
152 'creditmemoFactory' => $this->creditmemoFactoryMock,
153 'commentFactory' => $this->commentFactoryMock,
154 'hydratorPool' => $this->hydratorPoolMock,
155 'orderRepository' => $this->orderRepositoryMock
160 private function commonFactoryFlow()
162 $this->creditmemoItemCreationMock->expects($this->once())
163 ->method(
'getOrderItemId')
165 $this->creditmemoItemCreationMock->expects($this->once())
168 $this->hydratorPoolMock->expects($this->exactly(2))
169 ->method(
'getHydrator')
172 [CreditmemoCreationArgumentsInterface::class, $this->hydratorMock],
173 [CreditmemoCommentCreationInterface::class, $this->hydratorMock],
176 $this->hydratorMock->expects($this->exactly(2))
179 [$this->commentCreationArgumentsMock, [
'shipping_amount' =>
'20.00']],
180 [$this->commentCreationMock, [
'comment' =>
'text']]
182 $this->commentFactoryMock->expects($this->once())
191 ->willReturn($this->commentMock);
192 $this->creditmemoMock->expects($this->once())
193 ->method(
'getEntityId')
195 $this->creditmemoMock->expects($this->once())
196 ->method(
'getStoreId')
198 $this->commentMock->expects($this->once())
199 ->method(
'setParentId')
202 $this->commentMock->expects($this->once())
203 ->method(
'setStoreId')
206 $this->commentMock->expects($this->once())
207 ->method(
'setIsCustomerNotified')
210 $this->commentMock->expects($this->once())
211 ->method(
'setCreditmemo')
212 ->with($this->creditmemoMock)
218 $this->commonFactoryFlow();
219 $this->creditmemoFactoryMock->expects($this->once())
220 ->method(
'createByOrder')
224 'shipping_amount' =>
'20.00',
228 ->willReturn($this->creditmemoMock);
229 $this->factory->createFromOrder(
231 [$this->creditmemoItemCreationMock],
232 $this->commentCreationMock,
234 $this->commentCreationArgumentsMock
240 $this->commonFactoryFlow();
241 $this->creditmemoFactoryMock->expects($this->once())
242 ->method(
'createByInvoice')
246 'shipping_amount' =>
'20.00',
250 ->willReturn($this->creditmemoMock);
251 $this->orderRepositoryMock->expects($this->once())
253 ->willReturn($this->orderMock);
254 $this->invoiceMock->expects($this->once())
256 ->with($this->orderMock)
258 $this->factory->createFromInvoice(
260 [$this->creditmemoItemCreationMock],
261 $this->commentCreationMock,
263 $this->commentCreationArgumentsMock