|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Sales\Test\Unit\Model\Order; |
| 9 | + |
| 10 | +use Magento\Sales\Api\Data\ShippingAssignmentInterface; |
| 11 | +use Magento\Sales\Api\Data\ShippingAssignmentInterfaceFactory; |
| 12 | +use Magento\Sales\Model\OrderFactory; |
| 13 | +use Magento\Sales\Api\Data\OrderInterface; |
| 14 | +use Magento\Sales\Model\Order\ShippingAssignmentBuilder; |
| 15 | +use Magento\Sales\Model\Order\ShippingBuilderFactory; |
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +class ShippingAssignmentBuilderTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var ShippingAssignmentBuilder |
| 23 | + */ |
| 24 | + private $shippingAssignmentBuilder; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var OrderFactory|MockObject |
| 28 | + */ |
| 29 | + private $orderFactory; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var ShippingAssignmentInterfaceFactory|Mockobject |
| 33 | + */ |
| 34 | + private $shippingAssignmentFactory; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var ShippingBuilderFactory|MockObject |
| 38 | + */ |
| 39 | + private $shippingBuilderFactory; |
| 40 | + |
| 41 | + /** |
| 42 | + * @inheirtDoc |
| 43 | + */ |
| 44 | + protected function setUp(): void |
| 45 | + { |
| 46 | + $this->orderFactory = $this->getMockBuilder(OrderFactory::class) |
| 47 | + ->disableOriginalConstructor() |
| 48 | + ->getMock(); |
| 49 | + $this->shippingAssignmentFactory = $this->getMockBuilder(ShippingAssignmentInterfaceFactory::class) |
| 50 | + ->disableOriginalConstructor() |
| 51 | + ->getMock(); |
| 52 | + $this->shippingBuilderFactory = $this->getMockBuilder(ShippingBuilderFactory::class) |
| 53 | + ->disableOriginalConstructor() |
| 54 | + ->getMock(); |
| 55 | + $this->shippingAssignmentBuilder = new ShippingAssignmentBuilder( |
| 56 | + $this->orderFactory, |
| 57 | + $this->shippingAssignmentFactory, |
| 58 | + $this->shippingBuilderFactory |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Test for case when order is provided instead of order_id |
| 64 | + * |
| 65 | + * @return void |
| 66 | + */ |
| 67 | + public function testCreateWithOrder() : void |
| 68 | + { |
| 69 | + $order = $this->getMockBuilder(OrderInterface::class) |
| 70 | + ->getMockForAbstractClass(); |
| 71 | + $this->shippingAssignmentBuilder->setOrder($order); |
| 72 | + $order->expects($this->any()) |
| 73 | + ->method('getEntityId') |
| 74 | + ->willReturn(1); |
| 75 | + $this->orderFactory->expects($this->never()) |
| 76 | + ->method('create'); |
| 77 | + |
| 78 | + $this->shippingAssignmentBuilder->create(); |
| 79 | + } |
| 80 | +} |
0 commit comments