From db79dbfdf9bb5270b56b9f528d022eebe8ca50c6 Mon Sep 17 00:00:00 2001 From: freakphp Date: Sun, 17 Sep 2017 12:52:00 +0200 Subject: [PATCH 1/2] #10803 update OrderService to return correct bool value for cancel method --- .../Sales/Model/Service/OrderService.php | 3 ++- .../Unit/Model/Service/OrderServiceTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Service/OrderService.php b/app/code/Magento/Sales/Model/Service/OrderService.php index d187f7d8e4d24..2560d360138b5 100644 --- a/app/code/Magento/Sales/Model/Service/OrderService.php +++ b/app/code/Magento/Sales/Model/Service/OrderService.php @@ -87,7 +87,8 @@ public function __construct( public function cancel($id) { $order = $this->orderRepository->get($id); - if ((bool)$order->cancel()) { + if ((bool)$order->canCancel()) { + $order->cancel(); $this->orderRepository->save($order); return true; } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php b/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php index 14e1d3bac6a35..067f83d1e5b32 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php @@ -163,9 +163,30 @@ public function testCancel() $this->orderMock->expects($this->once()) ->method('cancel') ->willReturn($this->orderMock); + $this->orderMock->expects($this->once()) + ->method('canCancel') + ->willReturn(true); $this->assertTrue($this->orderService->cancel(123)); } + /** + * test for Order::cancel() fail case + */ + public function testCancelFailed() + { + $this->orderRepositoryMock->expects($this->once()) + ->method('get') + ->with(123) + ->willReturn($this->orderMock); + $this->orderMock->expects($this->never()) + ->method('cancel') + ->willReturn($this->orderMock); + $this->orderMock->expects($this->once()) + ->method('canCancel') + ->willReturn(false); + $this->assertFalse($this->orderService->cancel(123)); + } + public function testGetCommentsList() { $this->filterBuilderMock->expects($this->once()) From d4cddf7cb0773f351b80549854815cae4475db87 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Mon, 18 Sep 2017 12:22:00 +0200 Subject: [PATCH 2/2] magento/magento2#10919: update OrderService to return correct bool value - update OrderService to return correct bool value for cancel method - removed redundant type casting --- app/code/Magento/Sales/Model/Service/OrderService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Service/OrderService.php b/app/code/Magento/Sales/Model/Service/OrderService.php index 2560d360138b5..1eb3fad11278f 100644 --- a/app/code/Magento/Sales/Model/Service/OrderService.php +++ b/app/code/Magento/Sales/Model/Service/OrderService.php @@ -87,7 +87,7 @@ public function __construct( public function cancel($id) { $order = $this->orderRepository->get($id); - if ((bool)$order->canCancel()) { + if ($order->canCancel()) { $order->cancel(); $this->orderRepository->save($order); return true;