Skip to content

Commit 5324e71

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-54680: Order status change after Creditmemo creation through API
1 parent a3d6f1a commit 5324e71

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

app/code/Magento/Sales/Test/Unit/Model/RefundInvoiceTest.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Magento\Sales\Model\Order;
1919
use Magento\Sales\Model\Order\Config as OrderConfig;
2020
use Magento\Sales\Model\Order\Creditmemo\CreditmemoValidatorInterface;
21+
use Magento\Sales\Model\Order\Creditmemo\ItemCreationValidatorInterface;
22+
use Magento\Sales\Api\Data\CreditmemoItemCreationInterface;
2123
use Magento\Sales\Model\Order\CreditmemoDocumentFactory;
2224
use Magento\Sales\Model\Order\Invoice\InvoiceValidatorInterface;
2325
use Magento\Sales\Model\Order\OrderStateResolverInterface;
@@ -129,6 +131,16 @@ class RefundInvoiceTest extends \PHPUnit_Framework_TestCase
129131
*/
130132
private $adapterInterface;
131133

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+
132144
/**
133145
* @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
134146
*/
@@ -212,6 +224,14 @@ protected function setUp()
212224
->disableOriginalConstructor()
213225
->getMockForAbstractClass();
214226

227+
$this->creditmemoItemCreationMock = $this->getMockBuilder(CreditmemoItemCreationInterface::class)
228+
->disableOriginalConstructor()
229+
->getMockForAbstractClass();
230+
231+
$this->itemCreationValidatorMock = $this->getMockBuilder(ItemCreationValidatorInterface::class)
232+
->disableOriginalConstructor()
233+
->getMockForAbstractClass();
234+
215235
$this->refundInvoice = new RefundInvoice(
216236
$this->resourceConnectionMock,
217237
$this->orderStateResolverMock,
@@ -220,6 +240,7 @@ protected function setUp()
220240
$this->orderValidatorMock,
221241
$this->invoiceValidatorMock,
222242
$this->creditmemoValidatorMock,
243+
$this->itemCreationValidatorMock,
223244
$this->creditmemoRepositoryMock,
224245
$this->paymentAdapterMock,
225246
$this->creditmemoDocumentFactoryMock,
@@ -268,6 +289,10 @@ public function testOrderCreditmemo($invoiceId, $items, $notify, $appendComment)
268289
->method('validate')
269290
->with($this->invoiceMock)
270291
->willReturn([]);
292+
$this->itemCreationValidatorMock->expects($this->once())
293+
->method('validate')
294+
->with($this->creditmemoItemCreationMock)
295+
->willReturn([]);
271296
$this->paymentAdapterMock->expects($this->once())
272297
->method('refund')
273298
->with($this->creditmemoMock, $this->orderMock)
@@ -333,7 +358,7 @@ public function testOrderCreditmemo($invoiceId, $items, $notify, $appendComment)
333358
public function testDocumentValidationException()
334359
{
335360
$invoiceId = 1;
336-
$items = [1 => 2];
361+
$items = [1 => $this->creditmemoItemCreationMock];
337362
$notify = true;
338363
$appendComment = true;
339364
$errorMessages = ['error1', 'error2'];
@@ -367,6 +392,10 @@ public function testDocumentValidationException()
367392
->method('validate')
368393
->with($this->invoiceMock)
369394
->willReturn([]);
395+
$this->itemCreationValidatorMock->expects($this->once())
396+
->method('validate')
397+
->with($this->creditmemoItemCreationMock)
398+
->willReturn([]);
370399

371400
$this->assertEquals(
372401
$errorMessages,
@@ -388,7 +417,7 @@ public function testDocumentValidationException()
388417
public function testCouldNotCreditmemoException()
389418
{
390419
$invoiceId = 1;
391-
$items = [1 => 2];
420+
$items = [1 => $this->creditmemoItemCreationMock];
392421
$notify = true;
393422
$appendComment = true;
394423
$this->resourceConnectionMock->expects($this->once())
@@ -425,6 +454,10 @@ public function testCouldNotCreditmemoException()
425454
->method('validate')
426455
->with($this->invoiceMock)
427456
->willReturn([]);
457+
$this->itemCreationValidatorMock->expects($this->once())
458+
->method('validate')
459+
->with($this->creditmemoItemCreationMock)
460+
->willReturn([]);
428461
$e = new \Exception();
429462

430463
$this->paymentAdapterMock->expects($this->once())
@@ -452,9 +485,13 @@ public function testCouldNotCreditmemoException()
452485

453486
public function dataProvider()
454487
{
488+
$creditmemoItemCreationMock = $this->getMockBuilder(CreditmemoItemCreationInterface::class)
489+
->disableOriginalConstructor()
490+
->getMockForAbstractClass();
491+
455492
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],
458495
];
459496
}
460497
}

0 commit comments

Comments
 (0)