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 \Test \Objects ;
8
9
9
- use AspectMock \ Test as AspectMock ;
10
+ use Exception ;
10
11
use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
11
12
use Magento \FunctionalTestingFramework \DataGenerator \Objects \EntityDataObject ;
13
+ use Magento \FunctionalTestingFramework \Exceptions \TestReferenceException ;
14
+ use Magento \FunctionalTestingFramework \Exceptions \XmlException ;
12
15
use Magento \FunctionalTestingFramework \Page \Handlers \PageObjectHandler ;
16
+ use Magento \FunctionalTestingFramework \Page \Handlers \SectionObjectHandler ;
13
17
use Magento \FunctionalTestingFramework \Page \Objects \ElementObject ;
14
18
use Magento \FunctionalTestingFramework \Page \Objects \PageObject ;
15
- use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
16
- use Magento \FunctionalTestingFramework \Page \Handlers \SectionObjectHandler ;
17
19
use Magento \FunctionalTestingFramework \Page \Objects \SectionObject ;
18
- use Magento \FunctionalTestingFramework \Exceptions \ TestReferenceException ;
19
- use tests \ unit \ Util \ TestLoggingUtil ;
20
+ use Magento \FunctionalTestingFramework \Test \ Objects \ ActionObject ;
21
+ use ReflectionProperty ;
20
22
use tests \unit \Util \MagentoTestCase ;
23
+ use tests \unit \Util \TestLoggingUtil ;
21
24
22
25
/**
23
26
* Class ActionObjectTest
24
27
*/
25
28
class ActionObjectTest extends MagentoTestCase
26
29
{
27
30
/**
28
- * Before test functionality
31
+ * Before test functionality.
32
+ *
29
33
* @return void
30
34
*/
31
- public function setUp (): void
35
+ protected function setUp (): void
32
36
{
33
37
TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
34
38
}
35
39
36
40
/**
37
- * The order offset should be 0 when the action is instantiated with 'before'
41
+ * The order offset should be 0 when the action is instantiated with 'before'.
42
+ *
43
+ * @return void
38
44
*/
39
- public function testConstructOrderBefore ()
45
+ public function testConstructOrderBefore (): void
40
46
{
41
47
$ actionObject = new ActionObject ('stepKey ' , 'type ' , [], null , 'before ' );
42
48
$ this ->assertEquals (0 , $ actionObject ->getOrderOffset ());
43
49
}
44
50
45
51
/**
46
- * The order offset should be 1 when the action is instantiated with 'after'
52
+ * The order offset should be 1 when the action is instantiated with 'after'.
53
+ *
54
+ * @return void
47
55
*/
48
- public function testConstructOrderAfter ()
56
+ public function testConstructOrderAfter (): void
49
57
{
50
58
$ actionObject = new ActionObject ('stepKey ' , 'type ' , [], null , 'after ' );
51
59
$ this ->assertEquals (1 , $ actionObject ->getOrderOffset ());
52
60
}
53
61
54
62
/**
55
- * {{Section.element}} should be replaced with #theElementSelector
63
+ * {{Section.element}} should be replaced with #theElementSelector.
64
+ *
65
+ * @return void
66
+ * @throws TestReferenceException
67
+ * @throws XmlException
56
68
*/
57
- public function testResolveElementInSelector ()
69
+ public function testResolveElementInSelector (): void
58
70
{
59
71
// Set up mocks
60
72
$ actionObject = new ActionObject ('merge123 ' , 'fillField ' , [
@@ -76,9 +88,13 @@ public function testResolveElementInSelector()
76
88
}
77
89
78
90
/**
79
- * {{Section.element(param)}} should replace correctly with 'stringLiterals'
91
+ * {{Section.element(param)}} should replace correctly with 'stringLiterals'.
92
+ *
93
+ * @return void
94
+ * @throws TestReferenceException
95
+ * @throws XmlException
80
96
*/
81
- public function testResolveSelectorWithOneStringLiteral ()
97
+ public function testResolveSelectorWithOneStringLiteral (): void
82
98
{
83
99
$ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
84
100
'selector ' => "{{SectionObject.elementObject('stringliteral')}} " ,
@@ -99,9 +115,13 @@ public function testResolveSelectorWithOneStringLiteral()
99
115
}
100
116
101
117
/**
102
- * {{Section.element(param)}} should replace correctly with {{data.key}} references
118
+ * {{Section.element(param)}} should replace correctly with {{data.key}} references.
119
+ *
120
+ * @return void
121
+ * @throws TestReferenceException
122
+ * @throws XmlException
103
123
*/
104
- public function testResolveSelectorWithOneDataReference ()
124
+ public function testResolveSelectorWithOneDataReference (): void
105
125
{
106
126
$ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
107
127
'selector ' => "{{SectionObject.elementObject(dataObject.key)}} " ,
@@ -128,9 +148,13 @@ public function testResolveSelectorWithOneDataReference()
128
148
}
129
149
130
150
/**
131
- * {{Section.element(param)}} should replace correctly with $data.key$ references
151
+ * {{Section.element(param)}} should replace correctly with $data.key$ references.
152
+ *
153
+ * @return void
154
+ * @throws TestReferenceException
155
+ * @throws XmlException
132
156
*/
133
- public function testResolveSelectorWithOnePersistedReference ()
157
+ public function testResolveSelectorWithOnePersistedReference (): void
134
158
{
135
159
$ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
136
160
'selector ' => '{{SectionObject.elementObject($data.key$)}} ' ,
@@ -154,8 +178,12 @@ public function testResolveSelectorWithOnePersistedReference()
154
178
155
179
/**
156
180
* {{Section.element(param1,param2,param3)}} should replace correctly with all 3 data types.
181
+ *
182
+ * @return void
183
+ * @throws TestReferenceException
184
+ * @throws XmlException
157
185
*/
158
- public function testResolveSelectorWithManyParams ()
186
+ public function testResolveSelectorWithManyParams (): void
159
187
{
160
188
$ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
161
189
'selector ' => "{{SectionObject.elementObject('stringLiteral', data.key, \$data.key \$)}} " ,
@@ -182,9 +210,13 @@ public function testResolveSelectorWithManyParams()
182
210
}
183
211
184
212
/**
185
- * Timeout property on the ActionObject should be set if the ElementObject has a timeout
213
+ * Timeout property on the ActionObject should be set if the ElementObject has a timeout.
214
+ *
215
+ * @return void
216
+ * @throws TestReferenceException
217
+ * @throws XmlException
186
218
*/
187
- public function testTimeoutFromElement ()
219
+ public function testTimeoutFromElement (): void
188
220
{
189
221
// Set up mocks
190
222
$ actionObject = new ActionObject ('merge123 ' , 'click ' , [
@@ -201,20 +233,27 @@ public function testTimeoutFromElement()
201
233
}
202
234
203
235
/**
204
- * {{PageObject.url}} should be replaced with someUrl.html
236
+ * {{PageObject.url}} should be replaced with someUrl.html.
205
237
*
206
- * @throws /Exception
238
+ * @return void
239
+ * @throws Exception
207
240
*/
208
- public function testResolveUrl ()
241
+ public function testResolveUrl (): void
209
242
{
210
243
// Set up mocks
211
244
$ actionObject = new ActionObject ('merge123 ' , 'amOnPage ' , [
212
245
'url ' => '{{PageObject.url}} '
213
246
]);
214
247
$ pageObject = new PageObject ('PageObject ' , '/replacement/url.html ' , 'Test ' , [], false , "test " );
215
- $ instance = AspectMock::double (PageObjectHandler::class, ['getObject ' => $ pageObject ])
216
- ->make (); // bypass the private constructor
217
- AspectMock::double (PageObjectHandler::class, ['getInstance ' => $ instance ]);
248
+
249
+ $ instance = $ this ->createMock (PageObjectHandler::class);
250
+ $ instance
251
+ ->method ('getObject ' )
252
+ ->willReturn ($ pageObject );
253
+ // bypass the private constructor
254
+ $ property = new ReflectionProperty (PageObjectHandler::class, 'INSTANCE ' );
255
+ $ property ->setAccessible (true );
256
+ $ property ->setValue ($ instance );
218
257
219
258
// Call the method under test
220
259
$ actionObject ->resolveReferences ();
@@ -227,11 +266,12 @@ public function testResolveUrl()
227
266
}
228
267
229
268
/**
230
- * {{PageObject}} should not be replaced and should elicit a warning in console
269
+ * {{PageObject}} should not be replaced and should elicit a warning in console.
231
270
*
232
- * @throws /Exception
271
+ * @return void
272
+ * @throws Exception
233
273
*/
234
- public function testResolveUrlWithNoAttribute ()
274
+ public function testResolveUrlWithNoAttribute (): void
235
275
{
236
276
$ this ->expectException (TestReferenceException::class);
237
277
@@ -241,36 +281,51 @@ public function testResolveUrlWithNoAttribute()
241
281
]);
242
282
$ pageObject = new PageObject ('PageObject ' , '/replacement/url.html ' , 'Test ' , [], false , "test " );
243
283
$ pageObjectList = ["PageObject " => $ pageObject ];
244
- $ instance = AspectMock::double (
245
- PageObjectHandler::class,
246
- ['getObject ' => $ pageObject , 'getAllObjects ' => $ pageObjectList ]
247
- )->make (); // bypass the private constructor
248
- AspectMock::double (PageObjectHandler::class, ['getInstance ' => $ instance ]);
284
+
285
+ $ instance = $ this ->createMock (PageObjectHandler::class);
286
+ $ instance
287
+ ->method ('getObject ' )
288
+ ->willReturn ($ pageObject );
289
+ $ instance
290
+ ->method ('getAllObjects ' )
291
+ ->willReturn ($ pageObjectList );
292
+ // bypass the private constructor
293
+ $ property = new ReflectionProperty (PageObjectHandler::class, 'INSTANCE ' );
294
+ $ property ->setAccessible (true );
295
+ $ property ->setValue ($ instance );
249
296
250
297
// Call the method under test
251
298
$ actionObject ->resolveReferences ();
252
299
}
253
300
254
301
/**
255
- * {{PageObject.url(param)}} should be replaced
302
+ * {{PageObject.url(param)}} should be replaced.
303
+ *
304
+ * @return void
256
305
*/
257
- public function testResolveUrlWithOneParam ()
306
+ public function testResolveUrlWithOneParam (): void
258
307
{
259
308
$ this ->markTestIncomplete ('TODO ' );
260
309
}
261
310
262
311
/**
263
- * {{PageObject.url(param1,param2,param3)}} should be replaced
312
+ * {{PageObject.url(param1,param2,param3)}} should be replaced.
313
+ *
314
+ * @return void
264
315
*/
265
- public function testResolveUrlWithManyParams ()
316
+ public function testResolveUrlWithManyParams (): void
266
317
{
267
318
$ this ->markTestIncomplete ('TODO ' );
268
319
}
269
320
270
321
/**
271
- * {{EntityDataObject.key}} should be replaced with someDataValue
322
+ * {{EntityDataObject.key}} should be replaced with someDataValue.
323
+ *
324
+ * @return void
325
+ * @throws TestReferenceException
326
+ * @throws XmlException
272
327
*/
273
- public function testResolveDataInUserInput ()
328
+ public function testResolveDataInUserInput (): void
274
329
{
275
330
// Set up mocks
276
331
$ actionObject = new ActionObject ('merge123 ' , 'fillField ' , [
@@ -294,9 +349,13 @@ public function testResolveDataInUserInput()
294
349
}
295
350
296
351
/**
297
- * {{EntityDataObject.values}} should be replaced with ["value1","value2"]
352
+ * {{EntityDataObject.values}} should be replaced with ["value1","value2"].
353
+ *
354
+ * @return void
355
+ * @throws TestReferenceException
356
+ * @throws XmlException
298
357
*/
299
- public function testResolveArrayData ()
358
+ public function testResolveArrayData (): void
300
359
{
301
360
// Set up mocks
302
361
$ actionObject = new ActionObject ('merge123 ' , 'fillField ' , [
@@ -325,8 +384,12 @@ public function testResolveArrayData()
325
384
326
385
/**
327
386
* Action object should throw an exception if a reference to a parameterized selector has too few given args.
387
+ *
388
+ * @return void
389
+ * @throws TestReferenceException
390
+ * @throws XmlException
328
391
*/
329
- public function testTooFewArgumentException ()
392
+ public function testTooFewArgumentException (): void
330
393
{
331
394
$ this ->expectException (TestReferenceException::class);
332
395
@@ -343,8 +406,12 @@ public function testTooFewArgumentException()
343
406
344
407
/**
345
408
* Action object should throw an exception if a reference to a parameterized selector has too many given args.
409
+ *
410
+ * @return void
411
+ * @throws TestReferenceException
412
+ * @throws XmlException
346
413
*/
347
- public function testTooManyArgumentException ()
414
+ public function testTooManyArgumentException (): void
348
415
{
349
416
$ this ->expectException (TestReferenceException::class);
350
417
@@ -361,8 +428,12 @@ public function testTooManyArgumentException()
361
428
362
429
/**
363
430
* Action object should throw an exception if the timezone provided is not valid.
431
+ *
432
+ * @return void
433
+ * @throws TestReferenceException
434
+ * @throws XmlException
364
435
*/
365
- public function testInvalidTimezoneException ()
436
+ public function testInvalidTimezoneException (): void
366
437
{
367
438
$ this ->expectException (TestReferenceException::class);
368
439
@@ -374,23 +445,50 @@ public function testInvalidTimezoneException()
374
445
$ actionObject ->resolveReferences ();
375
446
}
376
447
377
- private function mockSectionHandlerWithElement ($ elementObject )
448
+ /**
449
+ * Mock section handler with the specified ElementObject.
450
+ *
451
+ * @param ElementObject $elementObject
452
+ *
453
+ * @return void
454
+ * @throws Exception
455
+ */
456
+ private function mockSectionHandlerWithElement (ElementObject $ elementObject ): void
378
457
{
379
458
$ sectionObject = new SectionObject ('SectionObject ' , ['elementObject ' => $ elementObject ]);
380
- $ instance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ sectionObject ])
381
- ->make (); // bypass the private constructor
382
- AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ instance ]);
459
+ $ instance = $ this ->createMock (SectionObjectHandler::class);
460
+ $ instance
461
+ ->method ('getObject ' )
462
+ ->willReturn ($ sectionObject );
463
+ // bypass the private constructor
464
+ $ property = new ReflectionProperty (SectionObjectHandler::class, 'INSTANCE ' );
465
+ $ property ->setAccessible (true );
466
+ $ property ->setValue ($ instance );
383
467
}
384
468
385
- private function mockDataHandlerWithData ($ dataObject )
469
+ /**
470
+ * Mock data handler with the specified EntityDataObject.
471
+ *
472
+ * @param EntityDataObject $dataObject
473
+ *
474
+ * @return void
475
+ * @throws Exception
476
+ */
477
+ private function mockDataHandlerWithData (EntityDataObject $ dataObject ): void
386
478
{
387
- $ dataInstance = AspectMock::double (DataObjectHandler::class, ['getObject ' => $ dataObject ])
388
- ->make ();
389
- AspectMock::double (DataObjectHandler::class, ['getInstance ' => $ dataInstance ]);
479
+ $ dataInstance = $ this ->createMock (DataObjectHandler::class);
480
+ $ dataInstance
481
+ ->method ('getObject ' )
482
+ ->willReturn ($ dataObject );
483
+ // bypass the private constructor
484
+ $ property = new ReflectionProperty (DataObjectHandler::class, 'INSTANCE ' );
485
+ $ property ->setAccessible (true );
486
+ $ property ->setValue ($ dataInstance );
390
487
}
391
488
392
489
/**
393
- * After class functionality
490
+ * After class functionality.
491
+ *
394
492
* @return void
395
493
*/
396
494
public static function tearDownAfterClass (): void
0 commit comments