|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright 2015 Adobe |
| 3 | + * Copyright 2014 Adobe |
4 | 4 | * All Rights Reserved. |
5 | 5 | */ |
6 | 6 | declare(strict_types=1); |
|
21 | 21 | use PHPUnit\Framework\MockObject\MockObject; |
22 | 22 | use PHPUnit\Framework\TestCase; |
23 | 23 |
|
| 24 | +/** |
| 25 | + * |
| 26 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 27 | + */ |
24 | 28 | class InvoiceServiceTest extends TestCase |
25 | 29 | { |
26 | 30 | /** |
@@ -212,4 +216,59 @@ public function testSetVoid() |
212 | 216 |
|
213 | 217 | $this->assertTrue($this->invoiceService->setVoid($id)); |
214 | 218 | } |
| 219 | + |
| 220 | + public function testPrepareInvoiceSetsHistoryEntityNameWhenOriginalEntityTypePresent(): void |
| 221 | + { |
| 222 | + $orderRepository = $this->createMock(\Magento\Sales\Api\OrderRepositoryInterface::class); |
| 223 | + $orderConverter = $this->getMockBuilder(\Magento\Sales\Model\Convert\Order::class) |
| 224 | + ->disableOriginalConstructor()->getMock(); |
| 225 | + $serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class); |
| 226 | + |
| 227 | + $service = new InvoiceService( |
| 228 | + $this->repositoryMock, |
| 229 | + $this->commentRepositoryMock, |
| 230 | + $this->searchCriteriaBuilderMock, |
| 231 | + $this->filterBuilderMock, |
| 232 | + $this->invoiceNotifierMock, |
| 233 | + $orderRepository, |
| 234 | + $orderConverter, |
| 235 | + $serializer |
| 236 | + ); |
| 237 | + |
| 238 | + $order = $this->getMockBuilder(\Magento\Sales\Model\Order::class) |
| 239 | + ->disableOriginalConstructor() |
| 240 | + ->onlyMethods(['getAllItems', 'getEntityType', 'setHistoryEntityName', 'getInvoiceCollection']) |
| 241 | + ->getMock(); |
| 242 | + |
| 243 | + $invoice = $this->getMockBuilder(\Magento\Sales\Model\Order\Invoice::class) |
| 244 | + ->disableOriginalConstructor() |
| 245 | + ->onlyMethods(['setTotalQty', 'collectTotals']) |
| 246 | + ->getMock(); |
| 247 | + |
| 248 | + $invoiceCollection = $this->getMockBuilder(\Magento\Framework\Data\Collection::class) |
| 249 | + ->disableOriginalConstructor() |
| 250 | + ->onlyMethods(['addItem']) |
| 251 | + ->getMock(); |
| 252 | + |
| 253 | + $order->method('getAllItems')->willReturn([]); |
| 254 | + $order->method('getEntityType')->willReturn('order'); |
| 255 | + $order->method('getInvoiceCollection')->willReturn($invoiceCollection); |
| 256 | + |
| 257 | + $order->expects($this->once()) |
| 258 | + ->method('setHistoryEntityName') |
| 259 | + ->with('order'); |
| 260 | + |
| 261 | + $orderConverter->expects($this->once()) |
| 262 | + ->method('toInvoice') |
| 263 | + ->with($order) |
| 264 | + ->willReturn($invoice); |
| 265 | + |
| 266 | + $invoice->expects($this->once())->method('setTotalQty')->with(0); |
| 267 | + $invoice->expects($this->once())->method('collectTotals'); |
| 268 | + |
| 269 | + $invoiceCollection->expects($this->once())->method('addItem')->with($invoice); |
| 270 | + |
| 271 | + $result = $service->prepareInvoice($order, []); |
| 272 | + $this->assertInstanceOf(\Magento\Sales\Api\Data\InvoiceInterface::class, $result); |
| 273 | + } |
215 | 274 | } |
0 commit comments