Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeviceDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
13 
17 class DeviceDataBuilderTest extends \PHPUnit\Framework\TestCase
18 {
22  private $subjectReaderMock;
23 
27  private $paymentDataObjectMock;
28 
32  private $paymentInfoMock;
33 
37  private $builder;
38 
39  protected function setUp()
40  {
41  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
42  ->disableOriginalConstructor()
43  ->setMethods(['readPayment'])
44  ->getMock();
45 
46  $this->paymentDataObjectMock = $this->createMock(PaymentDataObjectInterface::class);
47 
48  $this->paymentInfoMock = $this->createMock(InfoInterface::class);
49 
50  $this->builder = new DeviceDataBuilder($this->subjectReaderMock);
51  }
52 
59  public function testBuild(array $paymentData, array $expected)
60  {
61  $subject = [
62  'payment' => $this->paymentDataObjectMock,
63  ];
64 
65  $this->subjectReaderMock->expects(static::once())
66  ->method('readPayment')
67  ->with($subject)
68  ->willReturn($this->paymentDataObjectMock);
69 
70  $this->paymentDataObjectMock->expects(static::once())
71  ->method('getPayment')
72  ->willReturn($this->paymentInfoMock);
73 
74  $this->paymentInfoMock->expects(static::once())
75  ->method('getAdditionalInformation')
76  ->willReturn($paymentData);
77 
78  $actual = $this->builder->build($subject);
79  static::assertEquals($expected, $actual);
80  }
81 
86  public function buildDataProvider()
87  {
88  return [
89  [
90  'paymentData' => [
91  'device_data' => '{correlation_id: 12s3jf9as}'
92  ],
93  'expected' => [
94  'deviceData' => '{correlation_id: 12s3jf9as}'
95  ]
96  ],
97  [
98  'paymentData' => [
99  'device_data' => null,
100  ],
101  'expected' => []
102  ],
103  [
104  'paymentData' => [
105  'deviceData' => '{correlation_id: 12s3jf9as}',
106  ],
107  'expected' => []
108  ],
109  [
110  'paymentData' => [],
111  'expected' => []
112  ]
113  ];
114  }
115 }