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 \Util ;
8
9
9
- use AspectMock \Proxy \Verifier ;
10
- use AspectMock \Test as AspectMock ;
11
- use Magento \FunctionalTestingFramework \ObjectManager \ObjectManager ;
12
- use Magento \FunctionalTestingFramework \ObjectManagerFactory ;
10
+ use Exception ;
11
+ use Magento \FunctionalTestingFramework \ObjectManager ;
13
12
use Magento \FunctionalTestingFramework \Test \Handlers \ActionGroupObjectHandler ;
14
13
use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
15
14
use Magento \FunctionalTestingFramework \Test \Parsers \ActionGroupDataParser ;
16
15
use Magento \FunctionalTestingFramework \Test \Parsers \TestDataParser ;
17
- use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
18
- use Monolog \Handler \TestHandler ;
19
- use Monolog \Logger ;
20
16
use PHPUnit \Framework \TestCase ;
17
+ use ReflectionProperty ;
18
+ use tests \unit \Util \MockModuleResolverBuilder ;
21
19
use tests \unit \Util \TestDataArrayBuilder ;
22
20
use tests \unit \Util \TestLoggingUtil ;
23
- use tests \unit \Util \MockModuleResolverBuilder ;
24
21
25
22
class ObjectExtensionUtilTest extends TestCase
26
23
{
27
24
/**
28
- * Before test functionality
25
+ * Before test functionality.
26
+ *
29
27
* @return void
28
+ * @throws Exception
30
29
*/
31
- public function setUp (): void
30
+ protected function setUp (): void
32
31
{
33
32
TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
34
33
$ resolverMock = new MockModuleResolverBuilder ();
35
34
$ resolverMock ->setup ();
36
35
}
37
36
38
37
/**
39
- * After class functionality
38
+ * After class functionality.
39
+ *
40
40
* @return void
41
41
*/
42
42
public static function tearDownAfterClass (): void
@@ -45,10 +45,12 @@ public static function tearDownAfterClass(): void
45
45
}
46
46
47
47
/**
48
- * Tests generating a test that extends another test
49
- * @throws \Exception
48
+ * Tests generating a test that extends another test.
49
+ *
50
+ * @return void
51
+ * @throws Exception
50
52
*/
51
- public function testGenerateExtendedTest ()
53
+ public function testGenerateExtendedTest (): void
52
54
{
53
55
$ mockActions = [
54
56
"mockStep " => ["nodeName " => "mockNode " , "stepKey " => "mockStep " ]
@@ -86,10 +88,12 @@ public function testGenerateExtendedTest()
86
88
}
87
89
88
90
/**
89
- * Tests generating a test that extends another test
90
- * @throws \Exception
91
+ * Tests generating a test that extends another test.
92
+ *
93
+ * @return void
94
+ * @throws Exception
91
95
*/
92
- public function testGenerateExtendedWithHooks ()
96
+ public function testGenerateExtendedWithHooks (): void
93
97
{
94
98
$ mockBeforeHooks = [
95
99
"beforeHookAction " => ["nodeName " => "mockNodeBefore " , "stepKey " => "mockStepBefore " ]
@@ -132,10 +136,12 @@ public function testGenerateExtendedWithHooks()
132
136
}
133
137
134
138
/**
135
- * Tests generating a test that extends another test
136
- * @throws \Exception
139
+ * Tests generating a test that extends another test.
140
+ *
141
+ * @return void
142
+ * @throws Exception
137
143
*/
138
- public function testExtendedTestNoParent ()
144
+ public function testExtendedTestNoParent (): void
139
145
{
140
146
$ testDataArrayBuilder = new TestDataArrayBuilder ();
141
147
$ mockExtendedTest = $ testDataArrayBuilder
@@ -158,10 +164,12 @@ public function testExtendedTestNoParent()
158
164
}
159
165
160
166
/**
161
- * Tests generating a test that extends another test
162
- * @throws \Exception
167
+ * Tests generating a test that extends another test.
168
+ *
169
+ * @return void
170
+ * @throws Exception
163
171
*/
164
- public function testExtendingExtendedTest ()
172
+ public function testExtendingExtendedTest (): void
165
173
{
166
174
$ testDataArrayBuilder = new TestDataArrayBuilder ();
167
175
$ mockParentTest = $ testDataArrayBuilder
@@ -200,10 +208,12 @@ public function testExtendingExtendedTest()
200
208
}
201
209
202
210
/**
203
- * Tests generating an action group that extends another action group
204
- * @throws \Exception
211
+ * Tests generating an action group that extends another action group.
212
+ *
213
+ * @return void
214
+ * @throws Exception
205
215
*/
206
- public function testGenerateExtendedActionGroup ()
216
+ public function testGenerateExtendedActionGroup (): void
207
217
{
208
218
$ mockSimpleActionGroup = [
209
219
"nodeName " => "actionGroup " ,
@@ -259,10 +269,12 @@ public function testGenerateExtendedActionGroup()
259
269
}
260
270
261
271
/**
262
- * Tests generating an action group that extends an action group that does not exist
263
- * @throws \Exception
272
+ * Tests generating an action group that extends an action group that does not exist.
273
+ *
274
+ * @return void
275
+ * @throws Exception
264
276
*/
265
- public function testGenerateExtendedActionGroupNoParent ()
277
+ public function testGenerateExtendedActionGroupNoParent (): void
266
278
{
267
279
$ mockExtendedActionGroup = [
268
280
"nodeName " => "actionGroup " ,
@@ -292,10 +304,12 @@ public function testGenerateExtendedActionGroupNoParent()
292
304
}
293
305
294
306
/**
295
- * Tests generating an action group that extends another action group that is already extended
296
- * @throws \Exception
307
+ * Tests generating an action group that extends another action group that is already extended.
308
+ *
309
+ * @return void
310
+ * @throws Exception
297
311
*/
298
- public function testExtendingExtendedActionGroup ()
312
+ public function testExtendingExtendedActionGroup (): void
299
313
{
300
314
$ mockParentActionGroup = [
301
315
"nodeName " => "actionGroup " ,
@@ -333,7 +347,7 @@ public function testExtendingExtendedActionGroup()
333
347
// parse and generate test object with mocked data
334
348
try {
335
349
ActionGroupObjectHandler::getInstance ()->getObject ('mockExtendedActionGroup ' );
336
- } catch (\ Exception $ e ) {
350
+ } catch (Exception $ e ) {
337
351
// validate log statement
338
352
TestLoggingUtil::getInstance ()->validateMockLogStatement (
339
353
'error ' ,
@@ -347,11 +361,12 @@ public function testExtendingExtendedActionGroup()
347
361
}
348
362
349
363
/**
350
- * Tests generating a test that extends a skipped parent test
364
+ * Tests generating a test that extends a skipped parent test.
351
365
*
352
- * @throws \Exception
366
+ * @return void
367
+ * @throws Exception
353
368
*/
354
- public function testExtendedTestSkippedParent ()
369
+ public function testExtendedTestSkippedParent (): void
355
370
{
356
371
$ testDataArrayBuilder = new TestDataArrayBuilder ();
357
372
$ mockParentTest = $ testDataArrayBuilder
@@ -384,43 +399,55 @@ public function testExtendedTestSkippedParent()
384
399
/**
385
400
* Function used to set mock for parser return and force init method to run between tests.
386
401
*
387
- * @param array $testData
388
- * @throws \Exception
402
+ * @param array|null $testData
403
+ * @param array|null $actionGroupData
404
+ *
405
+ * @return void
406
+ * @throws Exception
389
407
*/
390
- private function setMockTestOutput ($ testData = null , $ actionGroupData = null )
408
+ private function setMockTestOutput (array $ testData = null , array $ actionGroupData = null ): void
391
409
{
392
410
// clear test object handler value to inject parsed content
393
- $ property = new \ ReflectionProperty (TestObjectHandler::class, 'testObjectHandler ' );
411
+ $ property = new ReflectionProperty (TestObjectHandler::class, 'testObjectHandler ' );
394
412
$ property ->setAccessible (true );
395
413
$ property ->setValue (null );
396
414
397
415
// clear test object handler value to inject parsed content
398
- $ property = new \ ReflectionProperty (ActionGroupObjectHandler::class, 'instance ' );
416
+ $ property = new ReflectionProperty (ActionGroupObjectHandler::class, 'instance ' );
399
417
$ property ->setAccessible (true );
400
418
$ property ->setValue (null );
401
419
402
- $ mockDataParser = AspectMock::double (TestDataParser::class, ['readTestData ' => $ testData ])->make ();
403
- $ mockActionGroupParser = AspectMock::double (
404
- ActionGroupDataParser::class,
405
- ['readActionGroupData ' => $ actionGroupData ]
406
- )->make ();
407
- $ instance = AspectMock::double (
408
- ObjectManager::class,
409
- [
410
- 'create ' => function ($ className ) use (
411
- $ mockDataParser ,
412
- $ mockActionGroupParser
413
- ) {
414
- if ($ className == TestDataParser::class) {
415
- return $ mockDataParser ;
416
- }
417
- if ($ className == ActionGroupDataParser::class) {
418
- return $ mockActionGroupParser ;
420
+ $ mockDataParser = $ this ->createMock (TestDataParser::class);
421
+ $ mockDataParser
422
+ ->method ('readTestData ' )
423
+ ->willReturn ($ testData );
424
+
425
+ $ mockActionGroupParser = $ this ->createMock (ActionGroupDataParser::class);
426
+ $ mockActionGroupParser
427
+ ->method ('readActionGroupData ' )
428
+ ->willReturn ($ actionGroupData );
429
+
430
+ $ instance = $ this ->createMock (ObjectManager::class);
431
+ $ instance
432
+ ->method ('create ' )
433
+ ->will (
434
+ $ this ->returnCallback (
435
+ function ($ className ) use ($ mockDataParser , $ mockActionGroupParser ) {
436
+ if ($ className === TestDataParser::class) {
437
+ return $ mockDataParser ;
438
+ }
439
+
440
+ if ($ className === ActionGroupDataParser::class) {
441
+ return $ mockActionGroupParser ;
442
+ }
443
+
444
+ return null ;
419
445
}
420
- }
421
- ]
422
- )->make ();
423
- // bypass the private constructor
424
- AspectMock::double (ObjectManagerFactory::class, ['getObjectManager ' => $ instance ]);
446
+ )
447
+ );
448
+ // clear object manager value to inject expected instance
449
+ $ property = new ReflectionProperty (ObjectManager::class, 'instance ' );
450
+ $ property ->setAccessible (true );
451
+ $ property ->setValue ($ instance );
425
452
}
426
453
}
0 commit comments