Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThreeDSecureDataBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
14 use PHPUnit_Framework_MockObject_MockObject as MockObject;
15 
19 class ThreeDSecureDataBuilderTest extends \PHPUnit\Framework\TestCase
20 {
24  private $builder;
25 
29  private $configMock;
30 
34  private $paymentDOMock;
35 
39  private $orderMock;
40 
44  private $billingAddressMock;
45 
49  private $subjectReaderMock;
50 
54  private $storeId = 1;
55 
59  protected function setUp()
60  {
61  $this->initOrderMock();
62 
63  $this->paymentDOMock = $this->getMockBuilder(PaymentDataObjectInterface::class)
64  ->disableOriginalConstructor()
65  ->setMethods(['getOrder', 'getPayment'])
66  ->getMock();
67  $this->paymentDOMock->expects(static::once())
68  ->method('getOrder')
69  ->willReturn($this->orderMock);
70 
71  $this->configMock = $this->getMockBuilder(Config::class)
72  ->setMethods(['isVerify3DSecure', 'getThresholdAmount', 'get3DSecureSpecificCountries'])
73  ->disableOriginalConstructor()
74  ->getMock();
75  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
76  ->disableOriginalConstructor()
77  ->getMock();
78 
79  $this->builder = new ThreeDSecureDataBuilder($this->configMock, $this->subjectReaderMock);
80  }
81 
91  public function testBuild($verify, $thresholdAmount, $countryId, array $countries, array $expected)
92  {
93  $buildSubject = [
94  'payment' => $this->paymentDOMock,
95  'amount' => 25,
96  ];
97 
98  $this->configMock->expects(static::once())
99  ->method('isVerify3DSecure')
100  ->with(self::equalTo($this->storeId))
101  ->willReturn($verify);
102 
103  $this->configMock->expects(static::any())
104  ->method('getThresholdAmount')
105  ->with(self::equalTo($this->storeId))
106  ->willReturn($thresholdAmount);
107 
108  $this->configMock->expects(static::any())
109  ->method('get3DSecureSpecificCountries')
110  ->with(self::equalTo($this->storeId))
111  ->willReturn($countries);
112 
113  $this->billingAddressMock->expects(static::any())
114  ->method('getCountryId')
115  ->willReturn($countryId);
116 
117  $this->subjectReaderMock->expects(self::once())
118  ->method('readPayment')
119  ->with($buildSubject)
120  ->willReturn($this->paymentDOMock);
121  $this->subjectReaderMock->expects(self::once())
122  ->method('readAmount')
123  ->with($buildSubject)
124  ->willReturn(25);
125 
126  $result = $this->builder->build($buildSubject);
127  self::assertEquals($expected, $result);
128  }
129 
135  public function buildDataProvider()
136  {
137  return [
138  ['verify' => true, 'amount' => 20, 'countryId' => 'US', 'countries' => [], 'result' => [
139  'options' => [
140  'three_d_secure' => [
141  'required' => true
142  ]
143  ]
144  ]],
145  ['verify' => true, 'amount' => 0, 'countryId' => 'US', 'countries' => ['US', 'GB'], 'result' => [
146  'options' => [
147  'three_d_secure' => [
148  'required' => true
149  ]
150  ]
151  ]],
152  ['verify' => true, 'amount' => 40, 'countryId' => 'US', 'countries' => [], 'result' => []],
153  ['verify' => false, 'amount' => 40, 'countryId' => 'US', 'countries' => [], 'result' => []],
154  ['verify' => false, 'amount' => 20, 'countryId' => 'US', 'countries' => [], 'result' => []],
155  ['verify' => true, 'amount' => 20, 'countryId' => 'CA', 'countries' => ['US', 'GB'], 'result' => []],
156  ];
157  }
158 
164  private function initOrderMock()
165  {
166  $this->billingAddressMock = $this->getMockBuilder(AddressAdapter::class)
167  ->disableOriginalConstructor()
168  ->setMethods(['getCountryId'])
169  ->getMock();
170 
171  $this->orderMock = $this->getMockBuilder(OrderAdapter::class)
172  ->disableOriginalConstructor()
173  ->setMethods(['getBillingAddress', 'getStoreId'])
174  ->getMock();
175 
176  $this->orderMock->expects(static::any())
177  ->method('getBillingAddress')
178  ->willReturn($this->billingAddressMock);
179  $this->orderMock->method('getStoreId')
180  ->willReturn($this->storeId);
181  }
182 }
testBuild($verify, $thresholdAmount, $countryId, array $countries, array $expected)