Skip to content

Commit db79dbf

Browse files
committed
magento#10803 update OrderService to return correct bool value for cancel method
1 parent e649b4c commit db79dbf

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/code/Magento/Sales/Model/Service/OrderService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public function __construct(
8787
public function cancel($id)
8888
{
8989
$order = $this->orderRepository->get($id);
90-
if ((bool)$order->cancel()) {
90+
if ((bool)$order->canCancel()) {
91+
$order->cancel();
9192
$this->orderRepository->save($order);
9293
return true;
9394
}

app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,30 @@ public function testCancel()
163163
$this->orderMock->expects($this->once())
164164
->method('cancel')
165165
->willReturn($this->orderMock);
166+
$this->orderMock->expects($this->once())
167+
->method('canCancel')
168+
->willReturn(true);
166169
$this->assertTrue($this->orderService->cancel(123));
167170
}
168171

172+
/**
173+
* test for Order::cancel() fail case
174+
*/
175+
public function testCancelFailed()
176+
{
177+
$this->orderRepositoryMock->expects($this->once())
178+
->method('get')
179+
->with(123)
180+
->willReturn($this->orderMock);
181+
$this->orderMock->expects($this->never())
182+
->method('cancel')
183+
->willReturn($this->orderMock);
184+
$this->orderMock->expects($this->once())
185+
->method('canCancel')
186+
->willReturn(false);
187+
$this->assertFalse($this->orderService->cancel(123));
188+
}
189+
169190
public function testGetCommentsList()
170191
{
171192
$this->filterBuilderMock->expects($this->once())

0 commit comments

Comments
 (0)