Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OrderStateServiceTest.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Sales\Model\OrderFactory;
14 use PHPUnit_Framework_MockObject_MockObject as MockObject;
15 
16 class OrderStateServiceTest extends \PHPUnit\Framework\TestCase
17 {
21  private static $orderId = 123;
22 
26  private $orderFactory;
27 
31  private $orderManagement;
32 
36  private $commentsHistoryUpdater;
37 
41  private $caseEntity;
42 
46  private $order;
47 
51  private $orderStateService;
52 
56  protected function setUp()
57  {
58  $this->orderManagement = $this->getMockBuilder(OrderManagementInterface::class)
59  ->getMockForAbstractClass();
60 
61  $this->commentsHistoryUpdater = $this->getMockBuilder(CommentsHistoryUpdater::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64 
65  $this->orderFactory = $this->getMockBuilder(OrderFactory::class)
66  ->setMethods(['create'])
67  ->disableOriginalConstructor()
68  ->getMock();
69 
70  $this->order = $this->getMockBuilder(Order::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73  $this->order->expects($this->once())
74  ->method('load')
75  ->willReturnSelf();
76 
77  $this->orderFactory->expects($this->once())
78  ->method('create')
79  ->willReturn($this->order);
80 
81  $this->caseEntity = $this->getMockBuilder(CaseInterface::class)
82  ->disableOriginalConstructor()
83  ->getMockForAbstractClass();
84  $this->caseEntity->expects($this->once())
85  ->method('getOrderId')
86  ->willReturn(self::$orderId);
87 
88  $this->orderStateService = new OrderStateService(
89  $this->orderFactory,
90  $this->orderManagement,
91  $this->commentsHistoryUpdater
92  );
93  }
94 
103  public function testUpdateByCaseWithGuaranteePending($canHold, $hold, $addCommentCall)
104  {
105  $this->caseEntity->expects($this->once())
106  ->method('getGuaranteeDisposition')
107  ->willReturn(CaseInterface::GUARANTEE_PENDING);
108  $this->order->expects($this->any())
109  ->method('canHold')
110  ->willReturn($canHold);
111  $this->orderManagement->expects($this->any())
112  ->method('hold')
113  ->willReturn($hold);
114  $this->commentsHistoryUpdater->expects($this->exactly($addCommentCall))
115  ->method('addComment')
116  ->with(
117  $this->caseEntity,
118  __('Awaiting the Signifyd guarantee disposition.'),
120  );
121 
122  $this->orderStateService->updateByCase($this->caseEntity);
123  }
124 
129  {
130  return [
131  ['canHold' => true, 'hold' => true, 'addCommentCall' => 1],
132  ['canHold' => false, 'hold' => true, 'addCommentCall' => 0],
133  ['canHold' => true, 'hold' => false, 'addCommentCall' => 0],
134  ];
135  }
136 
144  public function testUpdateByCaseWithGuaranteeApproved($canUnhold, $unholdCall)
145  {
146  $this->caseEntity->expects($this->once())
147  ->method('getGuaranteeDisposition')
148  ->willReturn(CaseInterface::GUARANTEE_APPROVED);
149  $this->order->expects($this->any())
150  ->method('canUnhold')
151  ->willReturn($canUnhold);
152  $this->orderManagement->expects($this->exactly($unholdCall))
153  ->method('unHold');
154  $this->commentsHistoryUpdater->expects($this->never())
155  ->method('addComment');
156 
157  $this->orderStateService->updateByCase($this->caseEntity);
158  }
159 
164  {
165  return [
166  ['canUnhold' => true, 'unholdCall' => 1],
167  ['canUnhold' => false, 'unholdCall' => 0]
168  ];
169  }
170 
178  public function testUpdateByCaseWithGuaranteeDeclined($canHold, $holdCall)
179  {
180  $this->caseEntity->expects($this->once())
181  ->method('getGuaranteeDisposition')
182  ->willReturn(CaseInterface::GUARANTEE_DECLINED);
183  $this->order->expects($this->any())
184  ->method('canHold')
185  ->willReturn($canHold);
186  $this->orderManagement->expects($this->exactly($holdCall))
187  ->method('hold');
188  $this->commentsHistoryUpdater->expects($this->never())
189  ->method('addComment');
190 
191  $this->orderStateService->updateByCase($this->caseEntity);
192  }
193 
198  {
199  return [
200  ['canHold' => true, 'holdCall' => 1],
201  ['canHold' => false, 'holdCall' => 0]
202  ];
203  }
204 }
__()
Definition: __.php:13
testUpdateByCaseWithGuaranteePending($canHold, $hold, $addCommentCall)