Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
14 use PHPUnit_Framework_MockObject_MockObject as MockObject;
16 
20 class PaymentDataBuilderTest extends \PHPUnit\Framework\TestCase
21 {
22  const PAYMENT_METHOD_NONCE = 'nonce';
23 
27  private $builder;
28 
32  private $paymentMock;
33 
37  private $paymentDOMock;
38 
42  private $subjectReaderMock;
43 
47  private $orderMock;
48 
52  protected function setUp()
53  {
54  $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
55  $this->paymentMock = $this->getMockBuilder(Payment::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
59  ->disableOriginalConstructor()
60  ->getMock();
61  $this->orderMock = $this->createMock(OrderAdapterInterface::class);
62 
64  $config = $this->getMockBuilder(Config::class)
65  ->disableOriginalConstructor()
66  ->getMock();
67 
68  $this->builder = new PaymentDataBuilder($config, $this->subjectReaderMock);
69  }
70 
75  public function testBuildReadPaymentException(): void
76  {
77  $buildSubject = [];
78 
79  $this->subjectReaderMock->expects(self::once())
80  ->method('readPayment')
81  ->with($buildSubject)
82  ->willThrowException(new \InvalidArgumentException());
83 
84  $this->builder->build($buildSubject);
85  }
86 
91  public function testBuildReadAmountException(): void
92  {
93  $buildSubject = [
94  'payment' => $this->paymentDOMock,
95  'amount' => null,
96  ];
97 
98  $this->subjectReaderMock->expects(self::once())
99  ->method('readPayment')
100  ->with($buildSubject)
101  ->willReturn($this->paymentDOMock);
102  $this->subjectReaderMock->expects(self::once())
103  ->method('readAmount')
104  ->with($buildSubject)
105  ->willThrowException(new \InvalidArgumentException());
106 
107  $this->builder->build($buildSubject);
108  }
109 
113  public function testBuild(): void
114  {
115  $additionalData = [
116  [
119  ],
120  ];
121 
122  $expectedResult = [
125  PaymentDataBuilder::ORDER_ID => '000000101'
126  ];
127 
128  $buildSubject = [
129  'payment' => $this->paymentDOMock,
130  'amount' => 10.00,
131  ];
132 
133  $this->paymentMock->expects(self::exactly(count($additionalData)))
134  ->method('getAdditionalInformation')
135  ->willReturnMap($additionalData);
136 
137  $this->paymentDOMock->expects(self::once())
138  ->method('getPayment')
139  ->willReturn($this->paymentMock);
140 
141  $this->paymentDOMock->expects(self::once())
142  ->method('getOrder')
143  ->willReturn($this->orderMock);
144 
145  $this->subjectReaderMock->expects(self::once())
146  ->method('readPayment')
147  ->with($buildSubject)
148  ->willReturn($this->paymentDOMock);
149  $this->subjectReaderMock->expects(self::once())
150  ->method('readAmount')
151  ->with($buildSubject)
152  ->willReturn(10.00);
153 
154  $this->orderMock->expects(self::once())
155  ->method('getOrderIncrementId')
156  ->willReturn('000000101');
157 
158  self::assertEquals(
159  $expectedResult,
160  $this->builder->build($buildSubject)
161  );
162  }
163 }
$config
Definition: fraud_order.php:17