@@ -85,6 +85,11 @@ class MassCancelTest extends \PHPUnit\Framework\TestCase
85
85
*/
86
86
protected $filterMock;
87
87
88
+ /**
89
+ * @var \PHPUnit_Framework_MockObject_MockObject
90
+ */
91
+ private $orderManagementMock;
92
+
88
93
protected function setUp()
89
94
{
90
95
$objectManagerHelper = new ObjectManagerHelper($this);
@@ -145,12 +150,15 @@ protected function setUp()
145
150
$this->orderCollectionFactoryMock->expects($this->once())
146
151
->method('create')
147
152
->willReturn($this->orderCollectionMock);
153
+ $this->orderManagementMock = $this->createMock(\Magento\Sales\Api\OrderManagementInterface::class);
154
+
148
155
$this->massAction = $objectManagerHelper->getObject(
149
156
\Magento\Sales\Controller\Adminhtml\Order\MassCancel::class,
150
157
[
151
158
'context' => $this->contextMock,
152
159
'filter' => $this->filterMock,
153
- 'collectionFactory' => $this->orderCollectionFactoryMock
160
+ 'collectionFactory' => $this->orderCollectionFactoryMock,
161
+ 'orderManagement' => $this->orderManagementMock
154
162
]
155
163
);
156
164
}
@@ -161,6 +169,9 @@ protected function setUp()
161
169
*/
162
170
public function testExecuteCanCancelOneOrder()
163
171
{
172
+ $order1id = 100;
173
+ $order2id = 200;
174
+
164
175
$order1 = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
165
176
->disableOriginalConstructor()
166
177
->getMock();
@@ -175,20 +186,19 @@ public function testExecuteCanCancelOneOrder()
175
186
->willReturn($orders);
176
187
177
188
$order1->expects($this->once())
178
- ->method('canCancel ')
179
- ->willReturn(true );
180
- $order1->expects($this->once())
181
- ->method('cancel');
182
- $order1->expects($this->once() )
183
- ->method('save' );
189
+ ->method('getEntityId ')
190
+ ->willReturn($order1id );
191
+
192
+ $order2->expects($this->once())
193
+ ->method('getEntityId' )
194
+ ->willReturn($order2id );
184
195
185
196
$this->orderCollectionMock->expects($this->once())
186
197
->method('count')
187
198
->willReturn($countOrders);
188
199
189
- $order2->expects($this->once())
190
- ->method('canCancel')
191
- ->willReturn(false);
200
+ $this->orderManagementMock->expects($this->at(0))->method('cancel')->with($order1id)->willReturn(true);
201
+ $this->orderManagementMock->expects($this->at(1))->method('cancel')->with($order2id)->willReturn(false);
192
202
193
203
$this->messageManagerMock->expects($this->once())
194
204
->method('addError')
@@ -222,21 +232,23 @@ public function testExcludedCannotCancelOrders()
222
232
$orders = [$order1, $order2];
223
233
$countOrders = count($orders);
224
234
235
+ $order1->expects($this->once())
236
+ ->method('getEntityId')
237
+ ->willReturn(100);
238
+
239
+ $order2->expects($this->once())
240
+ ->method('getEntityId')
241
+ ->willReturn(200);
242
+
225
243
$this->orderCollectionMock->expects($this->any())
226
244
->method('getItems')
227
245
->willReturn([$order1, $order2]);
228
246
229
- $order1->expects($this->once())
230
- ->method('canCancel')
231
- ->willReturn(false);
232
-
233
247
$this->orderCollectionMock->expects($this->once())
234
248
->method('count')
235
249
->willReturn($countOrders);
236
250
237
- $order2->expects($this->once())
238
- ->method('canCancel')
239
- ->willReturn(false);
251
+ $this->orderManagementMock->expects($this->atLeastOnce())->method('cancel')->willReturn(false);
240
252
241
253
$this->messageManagerMock->expects($this->once())
242
254
->method('addError')
@@ -265,11 +277,10 @@ public function testException()
265
277
->willReturn([$order1]);
266
278
267
279
$order1->expects($this->once())
268
- ->method('canCancel')
269
- ->willReturn(true);
270
- $order1->expects($this->once())
271
- ->method('cancel')
272
- ->willThrowException($exception);
280
+ ->method('getEntityId')
281
+ ->willReturn(100);
282
+
283
+ $this->orderManagementMock->expects($this->atLeastOnce())->method('cancel')->willThrowException($exception);
273
284
274
285
$this->messageManagerMock->expects($this->once())
275
286
->method('addError')
0 commit comments