Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
ToOrderPaymentTest.php
Go to the documentation of this file.
1 <?php
8 
11 
15 class ToOrderPaymentTest extends \PHPUnit\Framework\TestCase
16 {
21 
25  protected $objectCopyMock;
26 
30  protected $paymentMock;
31 
35  protected $dataObjectHelper;
36 
40  protected $converter;
41 
42  protected function setUp()
43  {
44  $this->paymentMock = $this->createPartialMock(
45  \Magento\Quote\Model\Quote\Payment::class,
46  ['getCcNumber', 'getCcCid', 'getMethodInstance', 'getAdditionalInformation']
47  );
48  $this->objectCopyMock = $this->createMock(\Magento\Framework\DataObject\Copy::class);
49  $this->orderPaymentRepositoryMock = $this->getMockForAbstractClass(
50  \Magento\Sales\Api\OrderPaymentRepositoryInterface::class,
51  [],
52  '',
53  false,
54  false
55  );
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\Payment\ToOrderPayment::class,
60  [
61  'orderPaymentRepository' => $this->orderPaymentRepositoryMock,
62  'objectCopyService' => $this->objectCopyMock,
63  'dataObjectHelper' => $this->dataObjectHelper
64  ]
65  );
66  }
67 
71  public function testConvert()
72  {
73  $methodInterface = $this->getMockForAbstractClass(\Magento\Payment\Model\MethodInterface::class);
74 
75  $paymentData = ['test' => 'test2'];
76  $data = ['some_id' => 1];
77  $paymentMethodTitle = 'TestTitle';
78  $additionalInfo = ['token' => 'TOKEN-123'];
79 
80  $this->paymentMock->expects($this->once())->method('getMethodInstance')->willReturn($methodInterface);
81  $methodInterface->expects($this->once())->method('getTitle')->willReturn($paymentMethodTitle);
82  $this->objectCopyMock->expects($this->once())->method('getDataFromFieldset')->with(
83  'quote_convert_payment',
84  'to_order_payment',
85  $this->paymentMock
86  )->willReturn($paymentData);
87 
88  $this->paymentMock->expects($this->once())
89  ->method('getAdditionalInformation')
90  ->willReturn($additionalInfo);
91  $ccNumber = 123456798;
92  $ccCid = 1234;
93  $this->paymentMock->expects($this->once())
94  ->method('getCcNumber')
95  ->willReturn($ccNumber);
96  $this->paymentMock->expects($this->once())
97  ->method('getCcCid')
98  ->willReturn($ccCid);
99 
100  $orderPayment = $this->getMockForAbstractClass(
101  \Magento\Sales\Api\Data\OrderPaymentInterface::class,
102  [],
103  '',
104  false,
105  true,
106  true,
107  ['setCcNumber', 'setCcCid', 'setAdditionalInformation']
108  );
109  $orderPayment->expects($this->once())
110  ->method('setAdditionalInformation')
111  ->with(array_merge($additionalInfo, [Substitution::INFO_KEY_TITLE => $paymentMethodTitle]))
112  ->willReturnSelf();
113  $orderPayment->expects($this->once())
114  ->method('setCcNumber')
115  ->willReturnSelf();
116  $orderPayment->expects($this->once())
117  ->method('setCcCid')
118  ->willReturnSelf();
119 
120  $this->orderPaymentRepositoryMock->expects($this->once())->method('create')->willReturn($orderPayment);
121  $this->dataObjectHelper->expects($this->once())
122  ->method('populateWithArray')
123  ->with(
124  $orderPayment,
125  array_merge($paymentData, $data),
126  \Magento\Sales\Api\Data\OrderPaymentInterface::class
127  )
128  ->willReturnSelf();
129 
130  $this->assertSame($orderPayment, $this->converter->convert($this->paymentMock, $data));
131  }
132 }
$objectManager
Definition: bootstrap.php:17