18
18
use Magento \Sales \Model \Order ;
19
19
use Magento \Sales \Model \Order \Config as OrderConfig ;
20
20
use Magento \Sales \Model \Order \Creditmemo \CreditmemoValidatorInterface ;
21
+ use Magento \Sales \Model \Order \Creditmemo \ItemCreationValidatorInterface ;
22
+ use Magento \Sales \Api \Data \CreditmemoItemCreationInterface ;
21
23
use Magento \Sales \Model \Order \CreditmemoDocumentFactory ;
22
24
use Magento \Sales \Model \Order \Invoice \InvoiceValidatorInterface ;
23
25
use Magento \Sales \Model \Order \OrderStateResolverInterface ;
@@ -129,6 +131,16 @@ class RefundInvoiceTest extends \PHPUnit_Framework_TestCase
129
131
*/
130
132
private $ adapterInterface ;
131
133
134
+ /**
135
+ * @var CreditmemoItemCreationInterface|\PHPUnit_Framework_MockObject_MockObject
136
+ */
137
+ private $ creditmemoItemCreationMock ;
138
+
139
+ /**
140
+ * @var ItemCreationValidatorInterface|\PHPUnit_Framework_MockObject_MockObject
141
+ */
142
+ private $ itemCreationValidatorMock ;
143
+
132
144
/**
133
145
* @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
134
146
*/
@@ -212,6 +224,14 @@ protected function setUp()
212
224
->disableOriginalConstructor ()
213
225
->getMockForAbstractClass ();
214
226
227
+ $ this ->creditmemoItemCreationMock = $ this ->getMockBuilder (CreditmemoItemCreationInterface::class)
228
+ ->disableOriginalConstructor ()
229
+ ->getMockForAbstractClass ();
230
+
231
+ $ this ->itemCreationValidatorMock = $ this ->getMockBuilder (ItemCreationValidatorInterface::class)
232
+ ->disableOriginalConstructor ()
233
+ ->getMockForAbstractClass ();
234
+
215
235
$ this ->refundInvoice = new RefundInvoice (
216
236
$ this ->resourceConnectionMock ,
217
237
$ this ->orderStateResolverMock ,
@@ -220,6 +240,7 @@ protected function setUp()
220
240
$ this ->orderValidatorMock ,
221
241
$ this ->invoiceValidatorMock ,
222
242
$ this ->creditmemoValidatorMock ,
243
+ $ this ->itemCreationValidatorMock ,
223
244
$ this ->creditmemoRepositoryMock ,
224
245
$ this ->paymentAdapterMock ,
225
246
$ this ->creditmemoDocumentFactoryMock ,
@@ -268,6 +289,10 @@ public function testOrderCreditmemo($invoiceId, $items, $notify, $appendComment)
268
289
->method ('validate ' )
269
290
->with ($ this ->invoiceMock )
270
291
->willReturn ([]);
292
+ $ this ->itemCreationValidatorMock ->expects ($ this ->once ())
293
+ ->method ('validate ' )
294
+ ->with ($ this ->creditmemoItemCreationMock )
295
+ ->willReturn ([]);
271
296
$ this ->paymentAdapterMock ->expects ($ this ->once ())
272
297
->method ('refund ' )
273
298
->with ($ this ->creditmemoMock , $ this ->orderMock )
@@ -333,7 +358,7 @@ public function testOrderCreditmemo($invoiceId, $items, $notify, $appendComment)
333
358
public function testDocumentValidationException ()
334
359
{
335
360
$ invoiceId = 1 ;
336
- $ items = [1 => 2 ];
361
+ $ items = [1 => $ this -> creditmemoItemCreationMock ];
337
362
$ notify = true ;
338
363
$ appendComment = true ;
339
364
$ errorMessages = ['error1 ' , 'error2 ' ];
@@ -367,6 +392,10 @@ public function testDocumentValidationException()
367
392
->method ('validate ' )
368
393
->with ($ this ->invoiceMock )
369
394
->willReturn ([]);
395
+ $ this ->itemCreationValidatorMock ->expects ($ this ->once ())
396
+ ->method ('validate ' )
397
+ ->with ($ this ->creditmemoItemCreationMock )
398
+ ->willReturn ([]);
370
399
371
400
$ this ->assertEquals (
372
401
$ errorMessages ,
@@ -388,7 +417,7 @@ public function testDocumentValidationException()
388
417
public function testCouldNotCreditmemoException ()
389
418
{
390
419
$ invoiceId = 1 ;
391
- $ items = [1 => 2 ];
420
+ $ items = [1 => $ this -> creditmemoItemCreationMock ];
392
421
$ notify = true ;
393
422
$ appendComment = true ;
394
423
$ this ->resourceConnectionMock ->expects ($ this ->once ())
@@ -425,6 +454,10 @@ public function testCouldNotCreditmemoException()
425
454
->method ('validate ' )
426
455
->with ($ this ->invoiceMock )
427
456
->willReturn ([]);
457
+ $ this ->itemCreationValidatorMock ->expects ($ this ->once ())
458
+ ->method ('validate ' )
459
+ ->with ($ this ->creditmemoItemCreationMock )
460
+ ->willReturn ([]);
428
461
$ e = new \Exception ();
429
462
430
463
$ this ->paymentAdapterMock ->expects ($ this ->once ())
@@ -452,9 +485,13 @@ public function testCouldNotCreditmemoException()
452
485
453
486
public function dataProvider ()
454
487
{
488
+ $ creditmemoItemCreationMock = $ this ->getMockBuilder (CreditmemoItemCreationInterface::class)
489
+ ->disableOriginalConstructor ()
490
+ ->getMockForAbstractClass ();
491
+
455
492
return [
456
- 'TestWithNotifyTrue ' => [1 , [1 => 2 ], true , true ],
457
- 'TestWithNotifyFalse ' => [1 , [1 => 2 ], false , true ],
493
+ 'TestWithNotifyTrue ' => [1 , [1 => $ creditmemoItemCreationMock ], true , true ],
494
+ 'TestWithNotifyFalse ' => [1 , [1 => $ creditmemoItemCreationMock ], false , true ],
458
495
];
459
496
}
460
497
}
0 commit comments