Skip to content

Commit ef40bc5

Browse files
committed
AC-15401: order entity type change durring invoice
1 parent d13ee6a commit ef40bc5

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

app/code/Magento/Sales/Model/Service/InvoiceService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

app/code/Magento/Sales/Test/Unit/Model/Service/InvoiceServiceTest.php

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -212,4 +212,59 @@ public function testSetVoid()
212212

213213
$this->assertTrue($this->invoiceService->setVoid($id));
214214
}
215+
216+
public function testPrepareInvoiceSetsHistoryEntityNameWhenOriginalEntityTypePresent(): void
217+
{
218+
$orderRepository = $this->createMock(\Magento\Sales\Api\OrderRepositoryInterface::class);
219+
$orderConverter = $this->getMockBuilder(\Magento\Sales\Model\Convert\Order::class)
220+
->disableOriginalConstructor()->getMock();
221+
$serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
222+
223+
$service = new InvoiceService(
224+
$this->repositoryMock,
225+
$this->commentRepositoryMock,
226+
$this->searchCriteriaBuilderMock,
227+
$this->filterBuilderMock,
228+
$this->invoiceNotifierMock,
229+
$orderRepository,
230+
$orderConverter,
231+
$serializer
232+
);
233+
234+
$order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
235+
->disableOriginalConstructor()
236+
->onlyMethods(['getAllItems', 'getEntityType', 'setHistoryEntityName', 'getInvoiceCollection'])
237+
->getMock();
238+
239+
$invoice = $this->getMockBuilder(\Magento\Sales\Model\Order\Invoice::class)
240+
->disableOriginalConstructor()
241+
->onlyMethods(['setTotalQty', 'collectTotals'])
242+
->getMock();
243+
244+
$invoiceCollection = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
245+
->disableOriginalConstructor()
246+
->onlyMethods(['addItem'])
247+
->getMock();
248+
249+
$order->method('getAllItems')->willReturn([]);
250+
$order->method('getEntityType')->willReturn('order');
251+
$order->method('getInvoiceCollection')->willReturn($invoiceCollection);
252+
253+
$order->expects($this->once())
254+
->method('setHistoryEntityName')
255+
->with('order');
256+
257+
$orderConverter->expects($this->once())
258+
->method('toInvoice')
259+
->with($order)
260+
->willReturn($invoice);
261+
262+
$invoice->expects($this->once())->method('setTotalQty')->with(0);
263+
$invoice->expects($this->once())->method('collectTotals');
264+
265+
$invoiceCollection->expects($this->once())->method('addItem')->with($invoice);
266+
267+
$result = $service->prepareInvoice($order, []);
268+
$this->assertInstanceOf(\Magento\Sales\Api\Data\InvoiceInterface::class, $result);
269+
}
215270
}

0 commit comments

Comments
 (0)