|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright © Magento, Inc. All rights reserved. |
4 | | - * See COPYING.txt for license details. |
| 3 | + * Copyright 2020 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */ |
6 | 6 | declare(strict_types=1); |
7 | 7 |
|
@@ -212,4 +212,59 @@ public function testSetVoid() |
212 | 212 |
|
213 | 213 | $this->assertTrue($this->invoiceService->setVoid($id)); |
214 | 214 | } |
| 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 | + } |
215 | 270 | } |
0 commit comments