82 $this->orderRepositoryMock = $this->getMockBuilder(
83 \
Magento\Sales\Api\OrderRepositoryInterface::class
85 ->disableOriginalConstructor()
87 $this->orderStatusHistoryRepositoryMock = $this->getMockBuilder(
88 \
Magento\Sales\Api\OrderStatusHistoryRepositoryInterface::class
90 ->disableOriginalConstructor()
92 $this->searchCriteriaBuilderMock = $this->getMockBuilder(
93 \
Magento\Framework\Api\SearchCriteriaBuilder::class
95 ->disableOriginalConstructor()
97 $this->searchCriteriaMock = $this->getMockBuilder(
98 \
Magento\Framework\Api\SearchCriteria::class
100 ->disableOriginalConstructor()
102 $this->filterBuilderMock = $this->getMockBuilder(
103 \
Magento\Framework\Api\FilterBuilder::class
105 ->disableOriginalConstructor()
107 $this->filterMock = $this->getMockBuilder(
108 \
Magento\Framework\Api\Filter::class
110 ->disableOriginalConstructor()
112 $this->orderNotifierMock = $this->getMockBuilder(
113 \
Magento\Sales\Model\OrderNotifier::class
115 ->disableOriginalConstructor()
117 $this->orderMock = $this->getMockBuilder(
118 \
Magento\Sales\Model\Order::class
120 ->disableOriginalConstructor()
122 $this->orderStatusHistoryMock = $this->getMockBuilder(
125 ->disableOriginalConstructor()
127 $this->orderSearchResultMock = $this->getMockBuilder(
128 \
Magento\Sales\Api\
Data\OrderStatusHistorySearchResultInterface::class
130 ->disableOriginalConstructor()
132 $this->eventManagerMock = $this->getMockBuilder(
133 \
Magento\Framework\Event\ManagerInterface::class
135 ->disableOriginalConstructor()
137 $this->orderCommentSender = $this->getMockBuilder(
138 \
Magento\Sales\Model\
Order\Email\Sender\OrderCommentSender::class
140 ->disableOriginalConstructor()
143 $this->orderService = new \Magento\Sales\Model\Service\OrderService(
144 $this->orderRepositoryMock,
145 $this->orderStatusHistoryRepositoryMock,
146 $this->searchCriteriaBuilderMock,
147 $this->filterBuilderMock,
148 $this->orderNotifierMock,
149 $this->eventManagerMock,
150 $this->orderCommentSender
159 $this->orderRepositoryMock->expects($this->once())
162 ->willReturn($this->orderMock);
163 $this->orderMock->expects($this->once())
165 ->willReturn($this->orderMock);
166 $this->orderMock->expects($this->once())
167 ->method(
'canCancel')
169 $this->assertTrue($this->orderService->cancel(123));
177 $this->orderRepositoryMock->expects($this->once())
180 ->willReturn($this->orderMock);
181 $this->orderMock->expects($this->never())
183 ->willReturn($this->orderMock);
184 $this->orderMock->expects($this->once())
185 ->method(
'canCancel')
187 $this->assertFalse($this->orderService->cancel(123));
192 $this->filterBuilderMock->expects($this->once())
196 $this->filterBuilderMock->expects($this->once())
200 $this->filterBuilderMock->expects($this->once())
201 ->method(
'setConditionType')
204 $this->filterBuilderMock->expects($this->once())
206 ->willReturn($this->filterMock);
207 $this->searchCriteriaBuilderMock->expects($this->once())
208 ->method(
'addFilters')
209 ->with([$this->filterMock])
210 ->willReturn($this->filterBuilderMock);
211 $this->searchCriteriaBuilderMock->expects($this->once())
213 ->willReturn($this->searchCriteriaMock);
214 $this->orderStatusHistoryRepositoryMock->expects($this->once())
216 ->with($this->searchCriteriaMock)
217 ->willReturn($this->orderSearchResultMock);
218 $this->assertEquals($this->orderSearchResultMock, $this->orderService->getCommentsList(123));
223 $clearComment =
"Comment text here...";
224 $this->orderRepositoryMock->expects($this->once())
227 ->willReturn($this->orderMock);
228 $this->orderMock->expects($this->once())
229 ->method(
'addStatusHistory')
230 ->with($this->orderStatusHistoryMock)
231 ->willReturn($this->orderMock);
232 $this->orderStatusHistoryMock->expects($this->once())
233 ->method(
'getComment')
234 ->willReturn(
"<h1>" . $clearComment);
235 $this->orderRepositoryMock->expects($this->once())
237 ->with($this->orderMock)
239 $this->orderCommentSender->expects($this->once())
241 ->with($this->orderMock,
false, $clearComment);
242 $this->assertTrue($this->orderService->addComment(123, $this->orderStatusHistoryMock));
247 $this->orderRepositoryMock->expects($this->once())
250 ->willReturn($this->orderMock);
251 $this->orderNotifierMock->expects($this->once())
253 ->with($this->orderMock)
255 $this->assertTrue($this->orderService->notify(123));
260 $this->orderRepositoryMock->expects($this->once())
263 ->willReturn($this->orderMock);
264 $this->orderMock->expects($this->once())
265 ->method(
'getStatus')
266 ->willReturn(
'test-status');
267 $this->assertEquals(
'test-status', $this->orderService->getStatus(123));
272 $this->orderRepositoryMock->expects($this->once())
275 ->willReturn($this->orderMock);
276 $this->orderRepositoryMock->expects($this->once())
278 ->with($this->orderMock)
279 ->willReturn($this->orderMock);
280 $this->orderMock->expects($this->once())
282 ->willReturn($this->orderMock);
283 $this->assertTrue($this->orderService->hold(123));
288 $this->orderRepositoryMock->expects($this->once())
291 ->willReturn($this->orderMock);
292 $this->orderRepositoryMock->expects($this->once())
294 ->with($this->orderMock)
295 ->willReturn($this->orderMock);
296 $this->orderMock->expects($this->once())
298 ->willReturn($this->orderMock);
299 $this->assertTrue($this->orderService->unHold(123));
$searchCriteriaBuilderMock
$orderStatusHistoryRepositoryMock