3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
declare (strict_types=1 );
7
8
8
9
namespace Magento \Sales \Test \Unit \Model \Order \Payment ;
12
13
use Magento \Framework \Registry ;
13
14
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
14
15
use Magento \Payment \Helper \Data ;
15
- use Magento \Payment \Model \Method ;
16
16
use Magento \Payment \Model \Method \Substitution ;
17
17
use Magento \Payment \Model \MethodInterface ;
18
+ use Magento \Sales \Api \Data \OrderInterface ;
18
19
use Magento \Sales \Model \Order \Payment \Info ;
19
20
use PHPUnit \Framework \MockObject \MockObject ;
20
21
use PHPUnit \Framework \TestCase ;
22
+ use Magento \Framework \Exception \LocalizedException ;
21
23
24
+ /**
25
+ * Test for \Magento\Sales\Model\Order\Payment\Info.
26
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
+ */
22
28
class InfoTest extends TestCase
23
29
{
24
- /** @var \Magento\Sales\Model\Order\Payment\Info */
25
- protected $ info ;
26
-
27
- /** @var ObjectManagerHelper */
28
- protected $ objectManagerHelper ;
29
-
30
- /** @var Context|MockObject */
31
- protected $ contextMock ;
30
+ /**
31
+ * @var Info
32
+ */
33
+ private $ info ;
32
34
33
- /** @var Registry|MockObject */
34
- protected $ registryMock ;
35
+ /**
36
+ * @var Data|MockObject
37
+ */
38
+ private $ paymentHelperMock ;
35
39
36
- /** @var Data|MockObject */
37
- protected $ paymentHelperMock ;
40
+ /**
41
+ * @var EncryptorInterface|MockObject
42
+ */
43
+ private $ encryptorInterfaceMock ;
38
44
39
- /** @var EncryptorInterface|MockObject */
40
- protected $ encryptorInterfaceMock ;
45
+ /**
46
+ * @var Data|MockObject
47
+ */
48
+ private $ methodInstanceMock ;
41
49
42
- /** @var Data|MockObject */
43
- protected $ methodInstanceMock ;
50
+ /**
51
+ * @var OrderInterface|MockObject
52
+ */
53
+ private $ orderMock ;
44
54
55
+ /**
56
+ * @inheritdoc
57
+ */
45
58
protected function setUp (): void
46
59
{
47
- $ this -> contextMock = $ this ->createMock (Context::class);
48
- $ this -> registryMock = $ this ->createMock (Registry::class);
60
+ $ contextMock = $ this ->createMock (Context::class);
61
+ $ registryMock = $ this ->createMock (Registry::class);
49
62
$ this ->paymentHelperMock = $ this ->createPartialMock (Data::class, ['getMethodInstance ' ]);
50
63
$ this ->encryptorInterfaceMock = $ this ->getMockForAbstractClass (EncryptorInterface::class);
51
- $ this ->methodInstanceMock = $ this ->getMockBuilder (MethodInterface::class)
52
- -> getMockForAbstractClass ( );
64
+ $ this ->methodInstanceMock = $ this ->getMockForAbstractClass (MethodInterface::class);
65
+ $ this -> orderMock = $ this -> createMock (OrderInterface::class );
53
66
54
- $ this -> objectManagerHelper = new ObjectManagerHelper ($ this );
55
- $ this ->info = $ this -> objectManagerHelper ->getObject (
67
+ $ objectManagerHelper = new ObjectManagerHelper ($ this );
68
+ $ this ->info = $ objectManagerHelper ->getObject (
56
69
Info::class,
57
70
[
58
- 'context ' => $ this -> contextMock ,
59
- 'registry ' => $ this -> registryMock ,
71
+ 'context ' => $ contextMock ,
72
+ 'registry ' => $ registryMock ,
60
73
'paymentData ' => $ this ->paymentHelperMock ,
61
74
'encryptor ' => $ this ->encryptorInterfaceMock
62
75
]
63
76
);
77
+ $ this ->info ->setData ('order ' , $ this ->orderMock );
64
78
}
65
79
66
80
/**
81
+ * Get data cc number
82
+ *
67
83
* @dataProvider ccKeysDataProvider
68
84
* @param string $keyCc
69
85
* @param string $keyCcEnc
86
+ * @return void
70
87
*/
71
- public function testGetDataCcNumber ($ keyCc , $ keyCcEnc )
88
+ public function testGetDataCcNumber ($ keyCc , $ keyCcEnc ): void
72
89
{
73
90
// no data was set
74
91
$ this ->assertNull ($ this ->info ->getData ($ keyCc ));
75
92
76
93
// we set encrypted data
77
94
$ this ->info ->setData ($ keyCcEnc , $ keyCcEnc );
78
- $ this ->encryptorInterfaceMock ->expects ($ this ->once ())->method ('decrypt ' )->with ($ keyCcEnc )->willReturn (
79
- $ keyCc
80
- );
95
+ $ this ->encryptorInterfaceMock ->expects ($ this ->once ())
96
+ ->method ('decrypt ' )
97
+ ->with ($ keyCcEnc )
98
+ ->willReturn ($ keyCc );
99
+
81
100
$ this ->assertEquals ($ keyCc , $ this ->info ->getData ($ keyCc ));
82
101
}
83
102
@@ -86,22 +105,34 @@ public function testGetDataCcNumber($keyCc, $keyCcEnc)
86
105
*
87
106
* @return array
88
107
*/
89
- public function ccKeysDataProvider ()
108
+ public function ccKeysDataProvider (): array
90
109
{
91
110
return [
92
111
['cc_number ' , 'cc_number_enc ' ],
93
112
['cc_cid ' , 'cc_cid_enc ' ]
94
113
];
95
114
}
96
115
97
- public function testGetMethodInstanceWithRealMethod ()
116
+ /**
117
+ * Get method instance with real method
118
+ *
119
+ * @return void
120
+ */
121
+ public function testGetMethodInstanceWithRealMethod (): void
98
122
{
123
+ $ storeId = 2 ;
99
124
$ method = 'real_method ' ;
100
125
$ this ->info ->setData ('method ' , $ method );
101
126
127
+ $ this ->orderMock ->expects ($ this ->once ())
128
+ ->method ('getStoreId ' )
129
+ ->willReturn ($ storeId );
102
130
$ this ->methodInstanceMock ->expects ($ this ->once ())
103
131
->method ('setInfoInstance ' )
104
132
->with ($ this ->info );
133
+ $ this ->methodInstanceMock ->expects ($ this ->once ())
134
+ ->method ('setStore ' )
135
+ ->with ($ storeId );
105
136
106
137
$ this ->paymentHelperMock ->expects ($ this ->once ())
107
138
->method ('getMethodInstance ' )
@@ -111,7 +142,12 @@ public function testGetMethodInstanceWithRealMethod()
111
142
$ this ->info ->getMethodInstance ();
112
143
}
113
144
114
- public function testGetMethodInstanceWithUnrealMethod ()
145
+ /**
146
+ * Get method instance with unreal method
147
+ *
148
+ * @return void
149
+ */
150
+ public function testGetMethodInstanceWithUnrealMethod (): void
115
151
{
116
152
$ method = 'unreal_method ' ;
117
153
$ this ->info ->setData ('method ' , $ method );
@@ -133,15 +169,26 @@ public function testGetMethodInstanceWithUnrealMethod()
133
169
$ this ->info ->getMethodInstance ();
134
170
}
135
171
136
- public function testGetMethodInstanceWithNoMethod ()
172
+ /**
173
+ * Get method instance withot method
174
+ *
175
+ * @return void
176
+ */
177
+ public function testGetMethodInstanceWithNoMethod (): void
137
178
{
138
- $ this ->expectException (' Magento\Framework\Exception\ LocalizedException' );
179
+ $ this ->expectException (LocalizedException::class );
139
180
$ this ->expectExceptionMessage ('The payment method you requested is not available. ' );
181
+
140
182
$ this ->info ->setData ('method ' , false );
141
183
$ this ->info ->getMethodInstance ();
142
184
}
143
185
144
- public function testGetMethodInstanceRequestedMethod ()
186
+ /**
187
+ * Get method instance requested method
188
+ *
189
+ * @return void
190
+ */
191
+ public function testGetMethodInstanceRequestedMethod (): void
145
192
{
146
193
$ code = 'real_method ' ;
147
194
$ this ->info ->setData ('method ' , $ code );
@@ -160,40 +207,62 @@ public function testGetMethodInstanceRequestedMethod()
160
207
$ this ->assertSame ($ this ->methodInstanceMock , $ this ->info ->getMethodInstance ());
161
208
}
162
209
163
- public function testEncrypt ()
210
+ /**
211
+ * Encrypt test
212
+ *
213
+ * @return void
214
+ */
215
+ public function testEncrypt (): void
164
216
{
165
217
$ data = 'data ' ;
166
218
$ encryptedData = 'd1a2t3a4 ' ;
167
219
168
- $ this ->encryptorInterfaceMock ->expects ($ this ->once ())->method ('encrypt ' )->with ($ data )->willReturn (
169
- $ encryptedData
170
- );
220
+ $ this ->encryptorInterfaceMock ->expects ($ this ->once ())
221
+ ->method ('encrypt ' )
222
+ ->with ($ data )
223
+ ->willReturn ($ encryptedData );
224
+
171
225
$ this ->assertEquals ($ encryptedData , $ this ->info ->encrypt ($ data ));
172
226
}
173
227
174
- public function testDecrypt ()
228
+ /**
229
+ * Decrypt test
230
+ *
231
+ * @return void
232
+ */
233
+ public function testDecrypt (): void
175
234
{
176
235
$ data = 'data ' ;
177
236
$ encryptedData = 'd1a2t3a4 ' ;
178
237
179
- $ this ->encryptorInterfaceMock ->expects ($ this ->once ())->method ('decrypt ' )->with ($ encryptedData )->willReturn (
180
- $ data
181
- );
238
+ $ this ->encryptorInterfaceMock ->expects ($ this ->once ())
239
+ ->method ('decrypt ' )
240
+ ->with ($ encryptedData )
241
+ ->willReturn ($ data );
242
+
182
243
$ this ->assertEquals ($ data , $ this ->info ->decrypt ($ encryptedData ));
183
244
}
184
245
185
- public function testSetAdditionalInformationException ()
246
+ /**
247
+ * Set additional information exception
248
+ *
249
+ * @return void
250
+ */
251
+ public function testSetAdditionalInformationException (): void
186
252
{
187
- $ this ->expectException (' Magento\Framework\Exception\ LocalizedException' );
253
+ $ this ->expectException (LocalizedException::class );
188
254
$ this ->info ->setAdditionalInformation ('object ' , new \stdClass ());
189
255
}
190
256
191
257
/**
258
+ * Set additional info multiple types
259
+ *
192
260
* @dataProvider additionalInformationDataProvider
193
261
* @param mixed $key
194
262
* @param mixed $value
263
+ * @return void
195
264
*/
196
- public function testSetAdditionalInformationMultipleTypes ($ key , $ value = null )
265
+ public function testSetAdditionalInformationMultipleTypes ($ key , $ value = null ): void
197
266
{
198
267
$ this ->info ->setAdditionalInformation ($ key , $ value );
199
268
$ this ->assertEquals ($ value ? [$ key => $ value ] : $ key , $ this ->info ->getAdditionalInformation ());
@@ -204,23 +273,33 @@ public function testSetAdditionalInformationMultipleTypes($key, $value = null)
204
273
*
205
274
* @return array
206
275
*/
207
- public function additionalInformationDataProvider ()
276
+ public function additionalInformationDataProvider (): array
208
277
{
209
278
return [
210
279
[['key1 ' => 'data1 ' , 'key2 ' => 'data2 ' ], null ],
211
280
['key ' , 'data ' ]
212
281
];
213
282
}
214
283
215
- public function testGetAdditionalInformationByKey ()
284
+ /**
285
+ * Get additional info by key
286
+ *
287
+ * @return void
288
+ */
289
+ public function testGetAdditionalInformationByKey (): void
216
290
{
217
291
$ key = 'key ' ;
218
292
$ value = 'value ' ;
219
293
$ this ->info ->setAdditionalInformation ($ key , $ value );
220
294
$ this ->assertEquals ($ value , $ this ->info ->getAdditionalInformation ($ key ));
221
295
}
222
296
223
- public function testUnsAdditionalInformation ()
297
+ /**
298
+ * Unsetter additional info
299
+ *
300
+ * @return void
301
+ */
302
+ public function testUnsAdditionalInformation (): void
224
303
{
225
304
// set array to additional
226
305
$ data = ['key1 ' => 'data1 ' , 'key2 ' => 'data2 ' ];
@@ -236,7 +315,12 @@ public function testUnsAdditionalInformation()
236
315
$ this ->assertEmpty ($ this ->info ->unsAdditionalInformation ()->getAdditionalInformation ());
237
316
}
238
317
239
- public function testHasAdditionalInformation ()
318
+ /**
319
+ * Has additional info
320
+ *
321
+ * @return void
322
+ */
323
+ public function testHasAdditionalInformation (): void
240
324
{
241
325
$ this ->assertFalse ($ this ->info ->hasAdditionalInformation ());
242
326
@@ -248,7 +332,12 @@ public function testHasAdditionalInformation()
248
332
$ this ->assertTrue ($ this ->info ->hasAdditionalInformation ());
249
333
}
250
334
251
- public function testInitAdditionalInformationWithUnserialize ()
335
+ /**
336
+ * Init additional info with unserialize
337
+ *
338
+ * @return void
339
+ */
340
+ public function testInitAdditionalInformationWithUnserialize (): void
252
341
{
253
342
$ data = ['key1 ' => 'data1 ' , 'key2 ' => 'data2 ' ];
254
343
$ this ->info ->setData ('additional_information ' , $ data );
0 commit comments