Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
ToOrderTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class ToOrderTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $objectCopyMock;
19 
24 
28  protected $orderMock;
29 
33  protected $converter;
34 
38  protected $eventManagerMock;
39 
43  protected $dataObjectHelper;
44 
45  protected function setUp()
46  {
47  $this->orderDataFactoryMock = $this->createPartialMock(
48  \Magento\Sales\Api\Data\OrderInterfaceFactory::class,
49  ['create']
50  );
51  $this->objectCopyMock = $this->createMock(\Magento\Framework\DataObject\Copy::class);
52  $this->orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $this->eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
56  $this->dataObjectHelper = $this->createMock(\Magento\Framework\Api\DataObjectHelper::class);
57  $objectManager = new ObjectManager($this);
58  $this->converter = $objectManager->getObject(
59  \Magento\Quote\Model\Quote\Address\ToOrder::class,
60  [
61  'orderFactory' => $this->orderDataFactoryMock,
62  'objectCopyService' => $this->objectCopyMock,
63  'eventManager' => $this->eventManagerMock,
64  'dataObjectHelper' => $this->dataObjectHelper
65  ]
66  );
67  }
68 
69  public function testConvert()
70  {
71  $orderData = ['test' => 'test1'];
72  $data = ['test' => 'beer'];
73  $quoteId = 1;
74  $storeId = 777;
75 
76  $object = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
77  $quote = $this->createMock(\Magento\Quote\Model\Quote::class);
78  $object->expects($this->exactly(5))->method('getQuote')->willReturn($quote);
79  $quote->expects($this->once())->method('getId')->willReturn($quoteId);
80  $quote->expects($this->once())->method('getStoreId')->willReturn($storeId);
81  $this->objectCopyMock->expects($this->once())->method('getDataFromFieldset')->with(
82  'sales_convert_quote_address',
83  'to_order',
84  $object
85  )->willReturn($orderData);
86  $this->dataObjectHelper->expects($this->once())->method('populateWithArray')
87  ->with($this->orderMock, ['test' => 'beer'], \Magento\Sales\Api\Data\OrderInterface::class)
88  ->willReturnSelf();
89  $this->orderMock->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf();
90  $this->orderMock->expects($this->once())->method('setQuoteId')->with($quoteId)->willReturnSelf();
91  $this->orderDataFactoryMock->expects($this->once())->method('create')->willReturn($this->orderMock);
92  $this->eventManagerMock->expects($this->once())
93  ->method('dispatch')
94  ->with('sales_convert_quote_to_order', ['order' => $this->orderMock, 'quote' => $quote]);
95  $this->assertSame($this->orderMock, $this->converter->convert($object, $data));
96  }
97 }
$objectManager
Definition: bootstrap.php:17
$quote