@@ -152,72 +152,13 @@ public function testValidateWithWrongItemId()
152
152
);
153
153
}
154
154
155
- public function testValidateWithWrongRefundQty ()
156
- {
157
- $ orderId = 1 ;
158
- $ orderItemId = 1 ;
159
- $ qtyToRequest = 1.5 ;
160
- $ sku = 'test sku ' ;
161
- $ total = 0 ;
162
- $ expected = [
163
- __ (
164
- 'You cannot use decimal quantity to refund item "%1". ' ,
165
- $ sku
166
- ),
167
- __ ('The credit memo \'s total must be positive. ' )
168
- ];
169
- $ creditmemoMock = $ this ->getMockBuilder (CreditmemoInterface::class)
170
- ->disableOriginalConstructor ()
171
- ->getMockForAbstractClass ();
172
- $ creditmemoMock ->expects ($ this ->exactly (2 ))->method ('getOrderId ' )
173
- ->willReturn ($ orderId );
174
- $ creditmemoMock ->expects ($ this ->once ())->method ('getGrandTotal ' )
175
- ->willReturn ($ total );
176
- $ creditmemoItemMock = $ this ->getMockBuilder (
177
- CreditmemoItemInterface::class
178
- )->disableOriginalConstructor ()
179
- ->getMockForAbstractClass ();
180
- $ creditmemoItemMock ->expects ($ this ->exactly (2 ))->method ('getOrderItemId ' )
181
- ->willReturn ($ orderItemId );
182
- $ creditmemoItemMock ->expects ($ this ->never ())->method ('getSku ' )
183
- ->willReturn ($ sku );
184
- $ creditmemoItemMock ->expects ($ this ->atLeastOnce ())->method ('getQty ' )
185
- ->willReturn ($ qtyToRequest );
186
- $ creditmemoMock ->expects ($ this ->exactly (1 ))->method ('getItems ' )
187
- ->willReturn ([$ creditmemoItemMock ]);
188
-
189
- $ orderMock = $ this ->getMockBuilder (OrderInterface::class)
190
- ->disableOriginalConstructor ()
191
- ->getMockForAbstractClass ();
192
- $ orderItemMock = $ this ->getMockBuilder (Item::class)
193
- ->disableOriginalConstructor ()
194
- ->getMock ();
195
- $ creditmemoItemMock ->expects ($ this ->any ())->method ('getQty ' )
196
- ->willReturn ($ qtyToRequest );
197
- $ orderMock ->expects ($ this ->once ())->method ('getItems ' )
198
- ->willReturn ([$ orderItemMock ]);
199
- $ orderItemMock ->expects ($ this ->once ())->method ('getItemId ' )
200
- ->willReturn ($ orderItemId );
201
- $ orderItemMock ->expects ($ this ->any ())->method ('getSku ' )
202
- ->willReturn ($ sku );
203
-
204
- $ this ->orderRepositoryMock ->expects ($ this ->once ())
205
- ->method ('get ' )
206
- ->with ($ orderId )
207
- ->willReturn ($ orderMock );
208
-
209
- $ this ->assertEquals (
210
- $ expected ,
211
- $ this ->validator ->validate ($ creditmemoMock )
212
- );
213
- }
214
-
215
155
/**
216
156
* @param int $orderId
217
157
* @param int $orderItemId
218
158
* @param int $qtyToRequest
219
159
* @param int $qtyToRefund
220
160
* @param string $sku
161
+ * @param int $total
221
162
* @param array $expected
222
163
* @dataProvider dataProviderForValidateQty
223
164
*/
@@ -249,7 +190,7 @@ public function testValidate($orderId, $orderItemId, $qtyToRequest, $qtyToRefund
249
190
$ orderItemMock = $ this ->getMockBuilder (Item::class)
250
191
->disableOriginalConstructor ()
251
192
->getMock ();
252
- $ orderItemMock ->expects ($ this ->exactly ( 2 ))->method ('getQtyToRefund ' )
193
+ $ orderItemMock ->expects ($ this ->any ( ))->method ('getQtyToRefund ' )
253
194
->willReturn ($ qtyToRefund );
254
195
$ creditmemoItemMock ->expects ($ this ->any ())->method ('getQty ' )
255
196
->willReturn ($ qtyToRequest );
@@ -297,6 +238,21 @@ public function dataProviderForValidateQty()
297
238
'total ' => 15 ,
298
239
'expected ' => []
299
240
],
241
+ [
242
+ 'orderId ' => 1 ,
243
+ 'orderItemId ' => 1 ,
244
+ 'qtyToRequest ' => 1.5 ,
245
+ 'qtyToRefund ' => 1 ,
246
+ 'sku ' ,
247
+ 'total ' => 0 ,
248
+ 'expected ' => [
249
+ __ (
250
+ 'We found an invalid quantity to refund item "%1". ' ,
251
+ $ sku
252
+ ),
253
+ __ ('The credit memo \'s total must be positive. ' )
254
+ ]
255
+ ],
300
256
[
301
257
'orderId ' => 1 ,
302
258
'orderItemId ' => 1 ,
0 commit comments