3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace tests \unit \Magento \FunctionalTestFramework \DataGenerator \Handlers ;
8
9
9
- use AspectMock \Test as AspectMock ;
10
- use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
10
+ use Exception ;
11
11
use Magento \FunctionalTestingFramework \DataGenerator \Handlers \PersistedObjectHandler ;
12
- use Magento \FunctionalTestingFramework \DataGenerator \Parsers \DataProfileSchemaParser ;
13
12
use Magento \FunctionalTestingFramework \DataGenerator \Persist \CurlHandler ;
14
- use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
15
13
use Magento \FunctionalTestingFramework \Exceptions \TestReferenceException ;
16
- use Magento \FunctionalTestingFramework \ObjectManager ;
17
- use Magento \FunctionalTestingFramework \ObjectManagerFactory ;
14
+ use ReflectionProperty ;
18
15
use tests \unit \Util \MagentoTestCase ;
19
16
use tests \unit \Util \ObjectHandlerUtil ;
20
17
use tests \unit \Util \TestLoggingUtil ;
25
22
class PersistedObjectHandlerTest extends MagentoTestCase
26
23
{
27
24
/**
28
- * Before test functionality
29
- * @return void
25
+ * @inheritDoc
30
26
*/
31
27
public function setUp (): void
32
28
{
33
29
TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
34
30
}
35
31
36
- public function testCreateEntityWithNonExistingName ()
32
+ /**
33
+ * Validate testCreateEntityWithNonExistingName.
34
+ *
35
+ * @return void
36
+ * @throws TestReferenceException
37
+ */
38
+ public function testCreateEntityWithNonExistingName (): void
37
39
{
38
40
// Test Data and Variables
39
- $ entityName = " InvalidEntity " ;
40
- $ entityStepKey = " StepKey " ;
41
+ $ entityName = ' InvalidEntity ' ;
42
+ $ entityStepKey = ' StepKey ' ;
41
43
$ scope = PersistedObjectHandler::TEST_SCOPE ;
42
44
43
45
$ exceptionMessage = "Entity \"" . $ entityName . "\" does not exist. " .
44
46
"\nException occurred executing action at StepKey \"" . $ entityStepKey . "\"" ;
45
47
46
48
$ this ->expectException (TestReferenceException::class);
47
-
48
49
$ this ->expectExceptionMessage ($ exceptionMessage );
49
-
50
50
$ handler = PersistedObjectHandler::getInstance ();
51
51
52
52
// Call method
@@ -57,13 +57,19 @@ public function testCreateEntityWithNonExistingName()
57
57
);
58
58
}
59
59
60
- public function testCreateSimpleEntity ()
60
+ /**
61
+ * Validate testCreateSimpleEntity.
62
+ *
63
+ * @return void
64
+ * @throws TestReferenceException
65
+ */
66
+ public function testCreateSimpleEntity (): void
61
67
{
62
68
// Test Data and Variables
63
- $ entityName = " EntityOne " ;
64
- $ entityStepKey = " StepKey " ;
65
- $ dataKey = " testKey " ;
66
- $ dataValue = " testValue " ;
69
+ $ entityName = ' EntityOne ' ;
70
+ $ entityStepKey = ' StepKey ' ;
71
+ $ dataKey = ' testKey ' ;
72
+ $ dataValue = ' testValue ' ;
67
73
$ scope = PersistedObjectHandler::TEST_SCOPE ;
68
74
$ parserOutput = [
69
75
'entity ' => [
@@ -78,7 +84,7 @@ public function testCreateSimpleEntity()
78
84
]
79
85
]
80
86
];
81
- $ jsonResponse = "
87
+ $ jsonResponse = "
82
88
{
83
89
\"" . strtolower ($ dataKey ) . "\" : \"{$ dataValue }\"
84
90
}
@@ -100,13 +106,19 @@ public function testCreateSimpleEntity()
100
106
$ this ->assertEquals ($ dataValue , $ persistedValue );
101
107
}
102
108
103
- public function testDeleteSimpleEntity ()
109
+ /**
110
+ * Validate testDeleteSimpleEntity.
111
+ *
112
+ * @return void
113
+ * @throws TestReferenceException
114
+ */
115
+ public function testDeleteSimpleEntity (): void
104
116
{
105
117
// Test Data and Variables
106
- $ entityName = " EntityOne " ;
107
- $ entityStepKey = " StepKey " ;
108
- $ dataKey = " testKey " ;
109
- $ dataValue = " testValue " ;
118
+ $ entityName = ' EntityOne ' ;
119
+ $ entityStepKey = ' StepKey ' ;
120
+ $ dataKey = ' testKey ' ;
121
+ $ dataValue = ' testValue ' ;
110
122
$ scope = PersistedObjectHandler::TEST_SCOPE ;
111
123
$ parserOutput = [
112
124
'entity ' => [
@@ -121,7 +133,7 @@ public function testDeleteSimpleEntity()
121
133
]
122
134
]
123
135
];
124
- $ jsonResponse = "
136
+ $ jsonResponse = "
125
137
{
126
138
\"" . strtolower ($ dataKey ) . "\" : \"{$ dataValue }\"
127
139
}
@@ -148,13 +160,19 @@ public function testDeleteSimpleEntity()
148
160
$ this ->addToAssertionCount (1 );
149
161
}
150
162
151
- public function testGetSimpleEntity ()
163
+ /**
164
+ * Validate testGetSimpleEntity.
165
+ *
166
+ * @return void
167
+ * @throws Exception
168
+ */
169
+ public function testGetSimpleEntity (): void
152
170
{
153
171
// Test Data and Variables
154
- $ entityName = " EntityOne " ;
155
- $ entityStepKey = " StepKey " ;
156
- $ dataKey = " testKey " ;
157
- $ dataValue = " testValue " ;
172
+ $ entityName = ' EntityOne ' ;
173
+ $ entityStepKey = ' StepKey ' ;
174
+ $ dataKey = ' testKey ' ;
175
+ $ dataValue = ' testValue ' ;
158
176
$ scope = PersistedObjectHandler::TEST_SCOPE ;
159
177
$ parserOutput = [
160
178
'entity ' => [
@@ -169,7 +187,7 @@ public function testGetSimpleEntity()
169
187
]
170
188
]
171
189
];
172
- $ jsonResponse = "
190
+ $ jsonResponse = "
173
191
{
174
192
\"" . strtolower ($ dataKey ) . "\" : \"{$ dataValue }\"
175
193
}
@@ -191,16 +209,22 @@ public function testGetSimpleEntity()
191
209
$ this ->assertEquals ($ dataValue , $ persistedValue );
192
210
}
193
211
194
- public function testUpdateSimpleEntity ()
212
+ /**
213
+ * Validate testUpdateSimpleEntity.
214
+ *
215
+ * @return void
216
+ * @throws TestReferenceException
217
+ */
218
+ public function testUpdateSimpleEntity (): void
195
219
{
196
- $ this ->markTestSkipped (" Potential Bug in DataPersistenceHandler class " );
220
+ $ this ->markTestSkipped (' Potential Bug in DataPersistenceHandler class ' );
197
221
// Test Data and Variables
198
- $ entityName = " EntityOne " ;
199
- $ entityStepKey = " StepKey " ;
200
- $ dataKey = " testKey " ;
201
- $ dataValue = " testValue " ;
202
- $ updateName = " EntityTwo " ;
203
- $ updateValue = " newValue " ;
222
+ $ entityName = ' EntityOne ' ;
223
+ $ entityStepKey = ' StepKey ' ;
224
+ $ dataKey = ' testKey ' ;
225
+ $ dataValue = ' testValue ' ;
226
+ $ updateName = ' EntityTwo ' ;
227
+ $ updateValue = ' newValue ' ;
204
228
$ scope = PersistedObjectHandler::TEST_SCOPE ;
205
229
$ parserOutput = [
206
230
'entity ' => [
@@ -224,7 +248,7 @@ public function testUpdateSimpleEntity()
224
248
]
225
249
]
226
250
];
227
- $ jsonResponse = "
251
+ $ jsonResponse = "
228
252
{
229
253
\"" . strtolower ($ dataKey ) . "\" : \"{$ dataValue }\"
230
254
}
@@ -257,21 +281,27 @@ public function testUpdateSimpleEntity()
257
281
$ this ->assertEquals ($ updateValue , $ persistedValue );
258
282
}
259
283
260
- public function testRetrieveEntityAcrossScopes ()
284
+ /**
285
+ * Validate testRetrieveEntityAcrossScopes.
286
+ *
287
+ * @return void
288
+ * @throws TestReferenceException
289
+ */
290
+ public function testRetrieveEntityAcrossScopes (): void
261
291
{
262
292
// Test Data and Variables
263
- $ entityNameOne = " EntityOne " ;
264
- $ entityStepKeyOne = " StepKeyOne " ;
265
- $ dataKeyOne = " testKeyOne " ;
266
- $ dataValueOne = " testValueOne " ;
267
- $ entityNameTwo = " EntityTwo " ;
268
- $ entityStepKeyTwo = " StepKeyTwo " ;
269
- $ dataKeyTwo = " testKeyTwo " ;
270
- $ dataValueTwo = " testValueTwo " ;
271
- $ entityNameThree = " EntityThree " ;
272
- $ entityStepKeyThree = " StepKeyThree " ;
273
- $ dataKeyThree = " testKeyThree " ;
274
- $ dataValueThree = " testValueThree " ;
293
+ $ entityNameOne = ' EntityOne ' ;
294
+ $ entityStepKeyOne = ' StepKeyOne ' ;
295
+ $ dataKeyOne = ' testKeyOne ' ;
296
+ $ dataValueOne = ' testValueOne ' ;
297
+ $ entityNameTwo = ' EntityTwo ' ;
298
+ $ entityStepKeyTwo = ' StepKeyTwo ' ;
299
+ $ dataKeyTwo = ' testKeyTwo ' ;
300
+ $ dataValueTwo = ' testValueTwo ' ;
301
+ $ entityNameThree = ' EntityThree ' ;
302
+ $ entityStepKeyThree = ' StepKeyThree ' ;
303
+ $ dataKeyThree = ' testKeyThree ' ;
304
+ $ dataValueThree = ' testValueThree ' ;
275
305
276
306
$ parserOutputOne = [
277
307
'entity ' => [
@@ -368,16 +398,27 @@ public function testRetrieveEntityAcrossScopes()
368
398
}
369
399
370
400
/**
401
+ * Validate testRetrieveEntityValidField.
402
+ *
371
403
* @param string $name
372
404
* @param string $key
373
405
* @param string $value
374
406
* @param string $type
375
407
* @param string $scope
376
408
* @param string $stepKey
377
409
* @dataProvider entityDataProvider
410
+ *
411
+ * @return void
412
+ * @throws TestReferenceException
378
413
*/
379
- public function testRetrieveEntityValidField ($ name , $ key , $ value , $ type , $ scope , $ stepKey )
380
- {
414
+ public function testRetrieveEntityValidField (
415
+ string $ name ,
416
+ string $ key ,
417
+ string $ value ,
418
+ string $ type ,
419
+ string $ scope ,
420
+ string $ stepKey
421
+ ): void {
381
422
$ parserOutputOne = [
382
423
'entity ' => [
383
424
$ name => [
@@ -411,21 +452,30 @@ public function testRetrieveEntityValidField($name, $key, $value, $type, $scope,
411
452
}
412
453
413
454
/**
455
+ * Validate testRetrieveEntityInValidField.
456
+ *
414
457
* @param string $name
415
458
* @param string $key
416
459
* @param string $value
417
460
* @param string $type
418
461
* @param string $scope
419
462
* @param string $stepKey
420
463
* @dataProvider entityDataProvider
464
+ *
465
+ * @return void
421
466
* @throws TestReferenceException
422
- * @throws TestFrameworkException
423
467
*/
424
- public function testRetrieveEntityInValidField ($ name , $ key , $ value , $ type , $ scope , $ stepKey )
425
- {
426
- $ invalidDataKey = "invalidDataKey " ;
468
+ public function testRetrieveEntityInValidField (
469
+ string $ name ,
470
+ string $ key ,
471
+ string $ value ,
472
+ string $ type ,
473
+ string $ scope ,
474
+ string $ stepKey
475
+ ): void {
476
+ $ invalidDataKey = 'invalidDataKey ' ;
427
477
$ warnMsg = "Undefined field {$ invalidDataKey } in entity object with a stepKey of {$ stepKey }\n" ;
428
- $ warnMsg .= " Please fix the invalid reference. This will result in fatal error in next major release. " ;
478
+ $ warnMsg .= ' Please fix the invalid reference. This will result in fatal error in next major release. ' ;
429
479
430
480
$ parserOutputOne = [
431
481
'entity ' => [
@@ -465,8 +515,10 @@ public function testRetrieveEntityInValidField($name, $key, $value, $type, $scop
465
515
466
516
/**
467
517
* Data provider for testRetrieveEntityField
518
+ *
519
+ * @return array
468
520
*/
469
- public static function entityDataProvider ()
521
+ public static function entityDataProvider (): array
470
522
{
471
523
return [
472
524
['Entity1 ' , 'testKey1 ' , 'testValue1 ' , 'testType ' , PersistedObjectHandler::HOOK_SCOPE , 'StepKey1 ' ],
@@ -475,29 +527,45 @@ public static function entityDataProvider()
475
527
];
476
528
}
477
529
478
- public function mockCurlHandler ($ response )
530
+ /**
531
+ * Create mock curl handler.
532
+ *
533
+ * @param string $response
534
+ * @throws Exception
535
+ */
536
+ public function mockCurlHandler (string $ response ): void
479
537
{
480
- AspectMock::double (CurlHandler::class, [
481
- "__construct " => null ,
482
- "executeRequest " => $ response ,
483
- "getRequestDataArray " => [],
484
- "isContentTypeJson " => true
485
- ]);
538
+ $ mockCurlHandler = $ this ->createMock (CurlHandler::class);
539
+ $ mockCurlHandler ->expects ($ this ->any ())
540
+ ->method ('executeRequest ' )
541
+ ->willReturn ($ response );
542
+ $ mockCurlHandler ->expects ($ this ->once ())
543
+ ->method ('getRequestDataArray ' )
544
+ ->willReturn ([]);
545
+ $ mockCurlHandler ->expects ($ this ->once ())
546
+ ->method ('isContentTypeJson ' )
547
+ ->willReturn (true );
548
+
549
+ $ property = new ReflectionProperty (CurlHandler::class, "INSTANCE " );
550
+ $ property ->setAccessible (true );
551
+ $ property ->setValue ($ mockCurlHandler );
486
552
}
487
553
554
+ /**
555
+ * @inheritDoc
556
+ */
488
557
public function tearDown (): void
489
558
{
490
559
// Clear out Singleton between tests
491
- $ property = new \ ReflectionProperty (PersistedObjectHandler::class, " INSTANCE " );
560
+ $ property = new ReflectionProperty (PersistedObjectHandler::class, ' INSTANCE ' );
492
561
$ property ->setAccessible (true );
493
562
$ property ->setValue (null );
494
563
495
564
parent ::tearDown (); // TODO: Change the autogenerated stub
496
565
}
497
566
498
567
/**
499
- * After class functionality
500
- * @return void
568
+ * @inheritDoc
501
569
*/
502
570
public static function tearDownAfterClass (): void
503
571
{
0 commit comments