Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ToOrderItemTest.php
Go to the documentation of this file.
1 <?php
7 
11 class ToOrderItemTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $converter;
17 
22 
27 
31  protected $quoteItemMock;
32 
36  protected $productMock;
37 
41  protected $productTypeMock;
42 
46  protected $orderItemMock;
47 
48  protected function setUp()
49  {
50  $this->orderItemFactoryMock = $this->createPartialMock(
51  \Magento\Sales\Api\Data\OrderItemInterfaceFactory::class,
52  ['create']
53  );
54  $this->objectCopyServiceMock = $this->createMock(\Magento\Framework\DataObject\Copy::class);
55  $this->quoteItemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
56  $this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
57  $this->productTypeMock = $this->createMock(\Magento\Catalog\Model\Product\Type\Simple::class);
58  $this->orderItemMock = $this->createMock(\Magento\Sales\Model\Order\Item::class);
59  $dataObjectHelper = $this->createMock(\Magento\Framework\Api\DataObjectHelper::class);
60 
61  $this->converter = new \Magento\Quote\Model\Quote\Item\ToOrderItem(
62  $this->orderItemFactoryMock,
63  $this->objectCopyServiceMock,
65  );
66  }
67 
71  public function testConvert()
72  {
73  $this->quoteItemMock->expects($this->exactly(2))
74  ->method('getProduct')
75  ->willReturn($this->productMock);
76  $this->productMock->expects($this->once())
77  ->method('getTypeInstance')
78  ->willReturn($this->productTypeMock);
79  $this->productTypeMock->expects($this->once())
80  ->method('getOrderOptions')
81  ->with($this->productMock)
82  ->willReturn(['option']);
83  $this->objectCopyServiceMock->expects($this->at(0))
84  ->method('getDataFromFieldset')
85  ->with('quote_convert_item', 'to_order_item', $this->quoteItemMock)
86  ->willReturn([]);
87  $this->objectCopyServiceMock->expects($this->at(1))
88  ->method('getDataFromFieldset')
89  ->with('quote_convert_item', 'to_order_item_discount', $this->quoteItemMock)
90  ->willReturn([]);
91  $this->orderItemFactoryMock->expects($this->once())
92  ->method('create')
93  ->willReturn($this->orderItemMock);
94  $this->assertInstanceOf(
95  \Magento\Sales\Model\Order\Item::class,
96  $this->converter->convert($this->quoteItemMock, [])
97  );
98  }
99 }