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
10
use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
11
11
use Magento \FunctionalTestingFramework \Exceptions \TestReferenceException ;
12
12
use Magento \FunctionalTestingFramework \Page \Handlers \SectionObjectHandler ;
15
15
use Magento \FunctionalTestingFramework \Test \Objects \ActionGroupObject ;
16
16
use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
17
17
use Magento \FunctionalTestingFramework \Test \Objects \ArgumentObject ;
18
- use tests \ unit \ Util \ MagentoTestCase ;
18
+ use ReflectionProperty ;
19
19
use tests \unit \Util \ActionGroupObjectBuilder ;
20
20
use tests \unit \Util \EntityDataObjectBuilder ;
21
+ use tests \unit \Util \MagentoTestCase ;
21
22
use tests \unit \Util \TestLoggingUtil ;
22
23
23
24
class ActionGroupObjectTest extends MagentoTestCase
24
25
{
25
26
const ACTION_GROUP_MERGE_KEY = 'TestKey ' ;
26
27
27
28
/**
28
- * Before test functionality
29
+ * Before test functionality.
30
+ *
29
31
* @return void
30
32
*/
31
- public function setUp (): void
33
+ protected function setUp (): void
32
34
{
33
35
TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
34
36
}
35
37
36
38
/**
37
- * Tests a string literal in an action group
39
+ * Tests a string literal in an action group.
40
+ *
41
+ * @return void
42
+ * @throws TestReferenceException
38
43
*/
39
- public function testGetStepsWithDefaultCase ()
44
+ public function testGetStepsWithDefaultCase (): void
40
45
{
41
46
$ entity = (new EntityDataObjectBuilder ())
42
47
->withDataFields (['field1 ' => 'testValue ' ])
@@ -48,9 +53,12 @@ public function testGetStepsWithDefaultCase()
48
53
}
49
54
50
55
/**
51
- * Tests a data reference in an action group, replaced by the user
56
+ * Tests a data reference in an action group, replaced by the user.
57
+ *
58
+ * @return void
59
+ * @throws TestReferenceException
52
60
*/
53
- public function testGetStepsWithCustomArgs ()
61
+ public function testGetStepsWithCustomArgs (): void
54
62
{
55
63
$ this ->setEntityObjectHandlerReturn (function ($ entityName ) {
56
64
if ($ entityName == "data2 " ) {
@@ -87,8 +95,11 @@ public function testGetStepsWithCustomArgs()
87
95
88
96
/**
89
97
* Tests a data reference in an action group replaced with a persisted reference.
98
+ *
99
+ * @return void
100
+ * @throws TestReferenceException
90
101
*/
91
- public function testGetStepsWithPersistedArgs ()
102
+ public function testGetStepsWithPersistedArgs (): void
92
103
{
93
104
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
94
105
->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{arg1.field2}} ' ])])
@@ -110,8 +121,11 @@ public function testGetStepsWithPersistedArgs()
110
121
111
122
/**
112
123
* Tests a data reference in an action group replaced with a data.field reference.
124
+ *
125
+ * @return void
126
+ * @throws TestReferenceException
113
127
*/
114
- public function testGetStepsWithNoFieldArg ()
128
+ public function testGetStepsWithNoFieldArg (): void
115
129
{
116
130
$ this ->setEntityObjectHandlerReturn (function ($ entityName ) {
117
131
if ($ entityName == "data2 " ) {
@@ -130,8 +144,11 @@ public function testGetStepsWithNoFieldArg()
130
144
131
145
/**
132
146
* Tests a data reference in an action group resolved with its default state.
147
+ *
148
+ * @return void
149
+ * @throws TestReferenceException
133
150
*/
134
- public function testGetStepsWithNoArgs ()
151
+ public function testGetStepsWithNoArgs (): void
135
152
{
136
153
$ this ->setEntityObjectHandlerReturn (function ($ entityName ) {
137
154
if ($ entityName == "data1 " ) {
@@ -149,8 +166,11 @@ public function testGetStepsWithNoArgs()
149
166
150
167
/**
151
168
* Tests a parameterized section reference in an action group resolved with user args.
169
+ *
170
+ * @return void
171
+ * @throws TestReferenceException
152
172
*/
153
- public function testGetStepsWithParameterizedArg ()
173
+ public function testGetStepsWithParameterizedArg (): void
154
174
{
155
175
// Mock Entity Object Handler
156
176
$ this ->setEntityObjectHandlerReturn (function ($ entityName ) {
@@ -161,9 +181,14 @@ public function testGetStepsWithParameterizedArg()
161
181
// mock the section object handler response
162
182
$ element = new ElementObject ("element1 " , "textArea " , ".selector {{var1}} " , null , null , true );
163
183
$ section = new SectionObject ("testSection " , ["element1 " => $ element ]);
184
+ $ sectionInstance = $ this ->createMock (SectionObjectHandler::class);
185
+ $ sectionInstance
186
+ ->method ('getObject ' )
187
+ ->willReturn ($ section );
164
188
// bypass the private constructor
165
- $ sectionInstance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ section ])->make ();
166
- AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ sectionInstance ]);
189
+ $ property = new ReflectionProperty (SectionObjectHandler::class, 'INSTANCE ' );
190
+ $ property ->setAccessible (true );
191
+ $ property ->setValue ($ sectionInstance );
167
192
168
193
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
169
194
->withActionObjects (
@@ -183,8 +208,11 @@ public function testGetStepsWithParameterizedArg()
183
208
184
209
/**
185
210
* Tests a parameterized section reference in an action group resolved with user simpleArgs.
211
+ *
212
+ * @return void
213
+ * @throws TestReferenceException
186
214
*/
187
- public function testGetStepsWithParameterizedSimpleArg ()
215
+ public function testGetStepsWithParameterizedSimpleArg (): void
188
216
{
189
217
// Mock Entity Object Handler
190
218
$ this ->setEntityObjectHandlerReturn (function ($ entityName ) {
@@ -195,9 +223,15 @@ public function testGetStepsWithParameterizedSimpleArg()
195
223
// mock the section object handler response
196
224
$ element = new ElementObject ("element1 " , "textArea " , ".selector {{var1}} " , null , null , true );
197
225
$ section = new SectionObject ("testSection " , ["element1 " => $ element ]);
226
+
227
+ $ sectionInstance = $ this ->createMock (SectionObjectHandler::class);
228
+ $ sectionInstance
229
+ ->method ('getObject ' )
230
+ ->willReturn ($ section );
198
231
// bypass the private constructor
199
- $ sectionInstance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ section ])->make ();
200
- AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ sectionInstance ]);
232
+ $ property = new ReflectionProperty (SectionObjectHandler::class, 'INSTANCE ' );
233
+ $ property ->setAccessible (true );
234
+ $ property ->setValue ($ sectionInstance );
201
235
202
236
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
203
237
->withActionObjects (
@@ -221,8 +255,11 @@ public function testGetStepsWithParameterizedSimpleArg()
221
255
222
256
/**
223
257
* Tests a data reference in an action group resolved with a persisted reference used in another function.
258
+ *
259
+ * @return void
260
+ * @throws TestReferenceException
224
261
*/
225
- public function testGetStepsWithOuterScopePersistence ()
262
+ public function testGetStepsWithOuterScopePersistence (): void
226
263
{
227
264
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
228
265
->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{arg1.field1}} ' ])])
@@ -235,8 +272,10 @@ public function testGetStepsWithOuterScopePersistence()
235
272
236
273
/**
237
274
* Tests an action group with mismatching args.
275
+ *
276
+ * @return void
238
277
*/
239
- public function testExceptionOnMissingActions ()
278
+ public function testExceptionOnMissingActions (): void
240
279
{
241
280
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
242
281
->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
@@ -249,8 +288,10 @@ public function testExceptionOnMissingActions()
249
288
250
289
/**
251
290
* Tests an action group with missing args.
291
+ *
292
+ * @return void
252
293
*/
253
- public function testExceptionOnMissingArguments ()
294
+ public function testExceptionOnMissingArguments (): void
254
295
{
255
296
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
256
297
->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
@@ -262,10 +303,12 @@ public function testExceptionOnMissingArguments()
262
303
}
263
304
264
305
/**
265
- * Tests the stepKey replacement with "stepKey + invocationKey" process filter
266
- * Specific to actions that make it past a "require stepKey replacement" filter
306
+ * Tests the stepKey replacement with "stepKey + invocationKey" process filter.
307
+ * Specific to actions that make it past a "require stepKey replacement" filter.
308
+ *
309
+ * @return void
267
310
*/
268
- public function testStepKeyReplacementFilteredIn ()
311
+ public function testStepKeyReplacementFilteredIn (): void
269
312
{
270
313
$ createStepKey = "createDataStepKey " ;
271
314
$ updateStepKey = "updateDataStepKey " ;
@@ -293,10 +336,12 @@ public function testStepKeyReplacementFilteredIn()
293
336
}
294
337
295
338
/**
296
- * Tests the stepKey replacement with "stepKey + invocationKey" process filter
297
- * Specific to actions that make are removed by a "require stepKey replacement" filter
339
+ * Tests the stepKey replacement with "stepKey + invocationKey" process filter.
340
+ * Specific to actions that make are removed by a "require stepKey replacement" filter.
341
+ *
342
+ * @return void
298
343
*/
299
- public function testStepKeyReplacementFilteredOut ()
344
+ public function testStepKeyReplacementFilteredOut (): void
300
345
{
301
346
$ clickStepKey = "clickStepKey " ;
302
347
$ fillFieldStepKey = "fillFieldStepKey " ;
@@ -322,13 +367,26 @@ public function testStepKeyReplacementFilteredOut()
322
367
* duration of a single test case.
323
368
*
324
369
* @param mixed $return
370
+ *
325
371
* @return void
326
372
*/
327
- private function setEntityObjectHandlerReturn ($ return )
373
+ private function setEntityObjectHandlerReturn ($ return ): void
328
374
{
329
- $ instance = AspectMock::double (DataObjectHandler::class, ['getObject ' => $ return ])
330
- ->make (); // bypass the private constructor
331
- AspectMock::double (DataObjectHandler::class, ['getInstance ' => $ instance ]);
375
+ $ instance = $ this ->createMock (DataObjectHandler::class);
376
+
377
+ if (is_callable ($ return )) {
378
+ $ instance
379
+ ->method ('getObject ' )
380
+ ->will ($ this ->returnCallback ($ return ));
381
+ } else {
382
+ $ instance
383
+ ->method ('getObject ' )
384
+ ->willReturn ($ return );
385
+ }
386
+ // bypass the private constructor
387
+ $ property = new ReflectionProperty (DataObjectHandler::class, 'INSTANCE ' );
388
+ $ property ->setAccessible (true );
389
+ $ property ->setValue ($ instance );
332
390
}
333
391
334
392
/**
@@ -337,11 +395,15 @@ private function setEntityObjectHandlerReturn($return)
337
395
*
338
396
* @param array $actions
339
397
* @param array $expectedValue
340
- * @param string $expectedMergeKey
398
+ * @param string|null $expectedMergeKey
399
+ *
341
400
* @return void
342
401
*/
343
- private function assertOnMergeKeyAndActionValue ($ actions , $ expectedValue , $ expectedMergeKey = null )
344
- {
402
+ private function assertOnMergeKeyAndActionValue (
403
+ array $ actions ,
404
+ array $ expectedValue ,
405
+ ?string $ expectedMergeKey = null
406
+ ): void {
345
407
$ expectedMergeKey = $ expectedMergeKey ??
346
408
ActionGroupObjectBuilder::DEFAULT_ACTION_OBJECT_NAME . self ::ACTION_GROUP_MERGE_KEY ;
347
409
$ this ->assertArrayHasKey ($ expectedMergeKey , $ actions );
@@ -352,7 +414,8 @@ private function assertOnMergeKeyAndActionValue($actions, $expectedValue, $expec
352
414
}
353
415
354
416
/**
355
- * After class functionality
417
+ * After class functionality.
418
+ *
356
419
* @return void
357
420
*/
358
421
public static function tearDownAfterClass (): void
0 commit comments