3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Braintree \Test \Unit \Model \Paypal \Helper ;
7
9
8
- use Magento \Quote \Model \Quote ;
9
- use Magento \Quote \Model \Quote \Address ;
10
- use Magento \Quote \Model \Quote \Payment ;
11
- use Magento \Quote \Api \CartRepositoryInterface ;
12
- use Magento \Braintree \Model \Ui \PayPal \ConfigProvider ;
13
- use Magento \Braintree \Observer \DataAssignObserver ;
14
10
use Magento \Braintree \Gateway \Config \PayPal \Config ;
15
11
use Magento \Braintree \Model \Paypal \Helper \QuoteUpdater ;
12
+ use Magento \Braintree \Model \Ui \PayPal \ConfigProvider ;
13
+ use Magento \Braintree \Observer \DataAssignObserver ;
14
+ use Magento \Quote \Api \CartRepositoryInterface ;
16
15
use Magento \Quote \Api \Data \CartExtensionInterface ;
16
+ use Magento \Quote \Model \Quote ;
17
+ use Magento \Quote \Model \Quote \Address ;
18
+ use Magento \Quote \Model \Quote \Payment ;
19
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
17
20
18
21
/**
19
22
* Class QuoteUpdaterTest
20
23
*
21
- * @see \Magento\Braintree\Model\Paypal\Helper\QuoteUpdater
22
- *
23
24
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
25
*/
25
26
class QuoteUpdaterTest extends \PHPUnit \Framework \TestCase
26
27
{
27
28
const TEST_NONCE = '3ede7045-2aea-463e-9754-cd658ffeeb48 ' ;
28
29
29
30
/**
30
- * @var Config|\PHPUnit_Framework_MockObject_MockObject
31
+ * @var Config|MockObject
31
32
*/
32
- private $ configMock ;
33
+ private $ config ;
33
34
34
35
/**
35
- * @var CartRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
36
+ * @var CartRepositoryInterface|MockObject
36
37
*/
37
- private $ quoteRepositoryMock ;
38
+ private $ quoteRepository ;
38
39
39
40
/**
40
- * @var Address|\PHPUnit_Framework_MockObject_MockObject
41
+ * @var Address|MockObject
41
42
*/
42
- private $ billingAddressMock ;
43
+ private $ billingAddress ;
43
44
44
45
/**
45
- * @var Address|\PHPUnit_Framework_MockObject_MockObject
46
+ * @var Address|MockObject
46
47
*/
47
- private $ shippingAddressMock ;
48
+ private $ shippingAddress ;
48
49
49
50
/**
50
51
* @var QuoteUpdater
51
52
*/
52
53
private $ quoteUpdater ;
53
54
54
55
/**
55
- * @return void
56
+ * @inheritdoc
56
57
*/
57
58
protected function setUp ()
58
59
{
59
- $ this ->configMock = $ this ->getMockBuilder (Config::class)
60
+ $ this ->config = $ this ->getMockBuilder (Config::class)
60
61
->disableOriginalConstructor ()
61
62
->getMock ();
62
- $ this ->quoteRepositoryMock = $ this ->getMockBuilder (CartRepositoryInterface::class)
63
+ $ this ->quoteRepository = $ this ->getMockBuilder (CartRepositoryInterface::class)
63
64
->getMockForAbstractClass ();
64
65
65
- $ this ->billingAddressMock = $ this ->getMockBuilder (Address::class)
66
+ $ this ->billingAddress = $ this ->getMockBuilder (Address::class)
66
67
->setMethods (
67
68
[
68
69
'setLastname ' ,
@@ -77,9 +78,10 @@ protected function setUp()
77
78
'setShouldIgnoreValidation ' ,
78
79
'getEmail '
79
80
]
80
- )->disableOriginalConstructor ()
81
+ )
82
+ ->disableOriginalConstructor ()
81
83
->getMock ();
82
- $ this ->shippingAddressMock = $ this ->getMockBuilder (Address::class)
84
+ $ this ->shippingAddress = $ this ->getMockBuilder (Address::class)
83
85
->setMethods (
84
86
[
85
87
'setLastname ' ,
@@ -93,61 +95,61 @@ protected function setUp()
93
95
'setPostcode ' ,
94
96
'setShouldIgnoreValidation '
95
97
]
96
- )->disableOriginalConstructor ()
98
+ )
99
+ ->disableOriginalConstructor ()
97
100
->getMock ();
98
101
99
102
$ this ->quoteUpdater = new QuoteUpdater (
100
- $ this ->configMock ,
101
- $ this ->quoteRepositoryMock
103
+ $ this ->config ,
104
+ $ this ->quoteRepository
102
105
);
103
106
}
104
107
105
108
/**
106
- * @return void
109
+ * Checks if quote details can be update by the response from Braintree.
110
+ *
107
111
* @throws \Magento\Framework\Exception\LocalizedException
108
112
*/
109
- public function testExecute ()
113
+ public function testExecute (): void
110
114
{
111
115
$ details = $ this ->getDetails ();
112
- $ quoteMock = $ this ->getQuoteMock ();
113
- $ paymentMock = $ this ->getPaymentMock ();
116
+ $ quote = $ this ->getQuoteMock ();
117
+ $ payment = $ this ->getPaymentMock ();
114
118
115
- $ quoteMock ->expects (self ::once ())
116
- ->method ('getPayment ' )
117
- ->willReturn ($ paymentMock );
119
+ $ quote ->method ('getPayment ' )
120
+ ->willReturn ($ payment );
118
121
119
- $ paymentMock ->expects (self ::once ())
120
- ->method ('setMethod ' )
122
+ $ payment ->method ('setMethod ' )
121
123
->with (ConfigProvider::PAYPAL_CODE );
122
- $ paymentMock ->expects (self ::once ())
123
- ->method ('setAdditionalInformation ' )
124
+ $ payment ->method ('setAdditionalInformation ' )
124
125
->with (DataAssignObserver::PAYMENT_METHOD_NONCE , self ::TEST_NONCE );
125
126
126
- $ this ->updateQuoteStep ($ quoteMock , $ details );
127
+ $ this ->updateQuoteStep ($ quote , $ details );
127
128
128
- $ this ->quoteUpdater ->execute (self ::TEST_NONCE , $ details , $ quoteMock );
129
+ $ this ->quoteUpdater ->execute (self ::TEST_NONCE , $ details , $ quote );
129
130
}
130
131
131
132
/**
133
+ * Disables quote's addresses validation.
134
+ *
132
135
* @return void
133
136
*/
134
- private function disabledQuoteAddressValidationStep ()
137
+ private function disabledQuoteAddressValidationStep (): void
135
138
{
136
- $ this ->billingAddressMock ->expects (self ::once ())
137
- ->method ('setShouldIgnoreValidation ' )
139
+ $ this ->billingAddress ->method ('setShouldIgnoreValidation ' )
138
140
->with (true );
139
- $ this ->shippingAddressMock ->expects (self ::once ())
140
- ->method ('setShouldIgnoreValidation ' )
141
+ $ this ->shippingAddress ->method ('setShouldIgnoreValidation ' )
141
142
->with (true );
142
- $ this ->billingAddressMock ->expects (self ::once ())
143
- ->method ('getEmail ' )
143
+ $ this ->billingAddress ->method ('getEmail ' )
144
144
->willReturn ('bt_buyer_us@paypal.com ' );
145
145
}
146
146
147
147
/**
148
+ * Gets quote's details.
149
+ *
148
150
* @return array
149
151
*/
150
- private function getDetails ()
152
+ private function getDetails (): array
151
153
{
152
154
return [
153
155
'email ' => 'bt_buyer_us@paypal.com ' ,
@@ -177,54 +179,51 @@ private function getDetails()
177
179
}
178
180
179
181
/**
182
+ * Updates shipping address details.
183
+ *
180
184
* @param array $details
181
185
*/
182
- private function updateShippingAddressStep (array $ details )
186
+ private function updateShippingAddressStep (array $ details ): void
183
187
{
184
- $ this ->shippingAddressMock ->expects (self ::once ())
185
- ->method ('setLastname ' )
188
+ $ this ->shippingAddress ->method ('setLastname ' )
186
189
->with ($ details ['lastName ' ]);
187
- $ this ->shippingAddressMock ->expects (self ::once ())
188
- ->method ('setFirstname ' )
190
+ $ this ->shippingAddress ->method ('setFirstname ' )
189
191
->with ($ details ['firstName ' ]);
190
- $ this ->shippingAddressMock ->expects (self ::once ())
191
- ->method ('setEmail ' )
192
+ $ this ->shippingAddress ->method ('setEmail ' )
192
193
->with ($ details ['email ' ]);
193
- $ this ->shippingAddressMock ->expects (self ::once ())
194
- ->method ('setCollectShippingRates ' )
194
+ $ this ->shippingAddress ->method ('setCollectShippingRates ' )
195
195
->with (true );
196
196
197
- $ this ->updateAddressDataStep ($ this ->shippingAddressMock , $ details ['shippingAddress ' ]);
197
+ $ this ->updateAddressDataStep ($ this ->shippingAddress , $ details ['shippingAddress ' ]);
198
198
}
199
199
200
200
/**
201
- * @param \PHPUnit_Framework_MockObject_MockObject $addressMock
201
+ * Updates address details.
202
+ *
203
+ * @param MockObject $address
202
204
* @param array $addressData
203
205
*/
204
- private function updateAddressDataStep (\ PHPUnit_Framework_MockObject_MockObject $ addressMock , array $ addressData )
206
+ private function updateAddressDataStep (MockObject $ address , array $ addressData ): void
205
207
{
206
- $ addressMock ->expects (self ::once ())
207
- ->method ('setStreet ' )
208
+ $ address ->method ('setStreet ' )
208
209
->with ([$ addressData ['streetAddress ' ], $ addressData ['extendedAddress ' ]]);
209
- $ addressMock ->expects (self ::once ())
210
- ->method ('setCity ' )
210
+ $ address ->method ('setCity ' )
211
211
->with ($ addressData ['locality ' ]);
212
- $ addressMock ->expects (self ::once ())
213
- ->method ('setRegionCode ' )
212
+ $ address ->method ('setRegionCode ' )
214
213
->with ($ addressData ['region ' ]);
215
- $ addressMock ->expects (self ::once ())
216
- ->method ('setCountryId ' )
214
+ $ address ->method ('setCountryId ' )
217
215
->with ($ addressData ['countryCodeAlpha2 ' ]);
218
- $ addressMock ->expects (self ::once ())
219
- ->method ('setPostcode ' )
216
+ $ address ->method ('setPostcode ' )
220
217
->with ($ addressData ['postalCode ' ]);
221
218
}
222
219
223
220
/**
224
- * @param \PHPUnit_Framework_MockObject_MockObject $quoteMock
221
+ * Updates quote's address details.
222
+ *
223
+ * @param MockObject $quoteMock
225
224
* @param array $details
226
225
*/
227
- private function updateQuoteAddressStep (\ PHPUnit_Framework_MockObject_MockObject $ quoteMock , array $ details )
226
+ private function updateQuoteAddressStep (MockObject $ quoteMock , array $ details ): void
228
227
{
229
228
$ quoteMock ->expects (self ::exactly (2 ))
230
229
->method ('getIsVirtual ' )
@@ -235,64 +234,61 @@ private function updateQuoteAddressStep(\PHPUnit_Framework_MockObject_MockObject
235
234
}
236
235
237
236
/**
237
+ * Updates billing address details.
238
+ *
238
239
* @param array $details
239
240
*/
240
- private function updateBillingAddressStep (array $ details )
241
+ private function updateBillingAddressStep (array $ details ): void
241
242
{
242
- $ this ->configMock ->expects (self ::once ())
243
- ->method ('isRequiredBillingAddress ' )
243
+ $ this ->config ->method ('isRequiredBillingAddress ' )
244
244
->willReturn (true );
245
245
246
- $ this ->updateAddressDataStep ($ this ->billingAddressMock , $ details ['billingAddress ' ]);
246
+ $ this ->updateAddressDataStep ($ this ->billingAddress , $ details ['billingAddress ' ]);
247
247
248
- $ this ->billingAddressMock ->expects (self ::once ())
249
- ->method ('setLastname ' )
248
+ $ this ->billingAddress ->method ('setLastname ' )
250
249
->with ($ details ['lastName ' ]);
251
- $ this ->billingAddressMock ->expects (self ::once ())
252
- ->method ('setFirstname ' )
250
+ $ this ->billingAddress ->method ('setFirstname ' )
253
251
->with ($ details ['firstName ' ]);
254
- $ this ->billingAddressMock ->expects (self ::once ())
255
- ->method ('setEmail ' )
252
+ $ this ->billingAddress ->method ('setEmail ' )
256
253
->with ($ details ['email ' ]);
257
254
}
258
255
259
256
/**
260
- * @param \PHPUnit_Framework_MockObject_MockObject $quoteMock
257
+ * Updates quote details.
258
+ *
259
+ * @param MockObject $quote
261
260
* @param array $details
262
261
*/
263
- private function updateQuoteStep (\ PHPUnit_Framework_MockObject_MockObject $ quoteMock , array $ details )
262
+ private function updateQuoteStep (MockObject $ quote , array $ details ): void
264
263
{
265
- $ quoteMock ->expects (self ::once ())
266
- ->method ('setMayEditShippingAddress ' )
264
+ $ quote ->method ('setMayEditShippingAddress ' )
267
265
->with (false );
268
- $ quoteMock ->expects (self ::once ())
269
- ->method ('setMayEditShippingMethod ' )
266
+ $ quote ->method ('setMayEditShippingMethod ' )
270
267
->with (true );
271
268
272
- $ quoteMock ->expects (self ::exactly (2 ))
273
- ->method ('getShippingAddress ' )
274
- ->willReturn ($ this ->shippingAddressMock );
275
- $ quoteMock ->expects (self ::exactly (2 ))
269
+ $ quote ->method ('getShippingAddress ' )
270
+ ->willReturn ($ this ->shippingAddress );
271
+ $ quote ->expects (self ::exactly (2 ))
276
272
->method ('getBillingAddress ' )
277
- ->willReturn ($ this ->billingAddressMock );
273
+ ->willReturn ($ this ->billingAddress );
278
274
279
- $ this ->updateQuoteAddressStep ($ quoteMock , $ details );
275
+ $ this ->updateQuoteAddressStep ($ quote , $ details );
280
276
$ this ->disabledQuoteAddressValidationStep ();
281
277
282
- $ quoteMock ->expects (self ::once ())
283
- ->method ('collectTotals ' );
278
+ $ quote ->method ('collectTotals ' );
284
279
285
- $ this ->quoteRepositoryMock ->expects (self ::once ())
286
- ->method ('save ' )
287
- ->with ($ quoteMock );
280
+ $ this ->quoteRepository ->method ('save ' )
281
+ ->with ($ quote );
288
282
}
289
283
290
284
/**
291
- * @return Quote|\PHPUnit_Framework_MockObject_MockObject
285
+ * Creates a mock for Quote object.
286
+ *
287
+ * @return Quote|MockObject
292
288
*/
293
- private function getQuoteMock ()
289
+ private function getQuoteMock (): MockObject
294
290
{
295
- $ quoteMock = $ this ->getMockBuilder (Quote::class)
291
+ $ quote = $ this ->getMockBuilder (Quote::class)
296
292
->setMethods (
297
293
[
298
294
'getIsVirtual ' ,
@@ -304,25 +300,27 @@ private function getQuoteMock()
304
300
'getBillingAddress ' ,
305
301
'getExtensionAttributes '
306
302
]
307
- )->disableOriginalConstructor ()
303
+ )
304
+ ->disableOriginalConstructor ()
308
305
->getMock ();
309
306
310
- $ cartExtensionMock = $ this ->getMockBuilder (CartExtensionInterface::class)
307
+ $ cartExtension = $ this ->getMockBuilder (CartExtensionInterface::class)
311
308
->setMethods (['setShippingAssignments ' ])
312
309
->disableOriginalConstructor ()
313
310
->getMockForAbstractClass ();
314
311
315
- $ quoteMock ->expects (self ::any ())
316
- ->method ('getExtensionAttributes ' )
317
- ->willReturn ($ cartExtensionMock );
312
+ $ quote ->method ('getExtensionAttributes ' )
313
+ ->willReturn ($ cartExtension );
318
314
319
- return $ quoteMock ;
315
+ return $ quote ;
320
316
}
321
317
322
318
/**
323
- * @return Payment|\PHPUnit_Framework_MockObject_MockObject
319
+ * Creates a mock for Payment object.
320
+ *
321
+ * @return Payment|MockObject
324
322
*/
325
- private function getPaymentMock ()
323
+ private function getPaymentMock (): MockObject
326
324
{
327
325
return $ this ->getMockBuilder (Payment::class)
328
326
->disableOriginalConstructor ()
0 commit comments