33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
67
78namespace tests \unit \Magento \FunctionalTestFramework \Test \Util ;
89
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 ;
1312use Magento \FunctionalTestingFramework \Test \Handlers \ActionGroupObjectHandler ;
1413use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
1514use Magento \FunctionalTestingFramework \Test \Parsers \ActionGroupDataParser ;
1615use Magento \FunctionalTestingFramework \Test \Parsers \TestDataParser ;
17- use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
18- use Monolog \Handler \TestHandler ;
19- use Monolog \Logger ;
2016use PHPUnit \Framework \TestCase ;
17+ use ReflectionProperty ;
18+ use tests \unit \Util \MockModuleResolverBuilder ;
2119use tests \unit \Util \TestDataArrayBuilder ;
2220use tests \unit \Util \TestLoggingUtil ;
23- use tests \unit \Util \MockModuleResolverBuilder ;
2421
2522class ObjectExtensionUtilTest extends TestCase
2623{
2724 /**
28- * Before test functionality
25+ * Before test functionality.
26+ *
2927 * @return void
28+ * @throws Exception
3029 */
31- public function setUp (): void
30+ protected function setUp (): void
3231 {
3332 TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
3433 $ resolverMock = new MockModuleResolverBuilder ();
3534 $ resolverMock ->setup ();
3635 }
3736
3837 /**
39- * After class functionality
38+ * After class functionality.
39+ *
4040 * @return void
4141 */
4242 public static function tearDownAfterClass (): void
@@ -45,10 +45,12 @@ public static function tearDownAfterClass(): void
4545 }
4646
4747 /**
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
5052 */
51- public function testGenerateExtendedTest ()
53+ public function testGenerateExtendedTest (): void
5254 {
5355 $ mockActions = [
5456 "mockStep " => ["nodeName " => "mockNode " , "stepKey " => "mockStep " ]
@@ -86,10 +88,12 @@ public function testGenerateExtendedTest()
8688 }
8789
8890 /**
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
9195 */
92- public function testGenerateExtendedWithHooks ()
96+ public function testGenerateExtendedWithHooks (): void
9397 {
9498 $ mockBeforeHooks = [
9599 "beforeHookAction " => ["nodeName " => "mockNodeBefore " , "stepKey " => "mockStepBefore " ]
@@ -132,10 +136,12 @@ public function testGenerateExtendedWithHooks()
132136 }
133137
134138 /**
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
137143 */
138- public function testExtendedTestNoParent ()
144+ public function testExtendedTestNoParent (): void
139145 {
140146 $ testDataArrayBuilder = new TestDataArrayBuilder ();
141147 $ mockExtendedTest = $ testDataArrayBuilder
@@ -158,10 +164,12 @@ public function testExtendedTestNoParent()
158164 }
159165
160166 /**
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
163171 */
164- public function testExtendingExtendedTest ()
172+ public function testExtendingExtendedTest (): void
165173 {
166174 $ testDataArrayBuilder = new TestDataArrayBuilder ();
167175 $ mockParentTest = $ testDataArrayBuilder
@@ -200,10 +208,12 @@ public function testExtendingExtendedTest()
200208 }
201209
202210 /**
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
205215 */
206- public function testGenerateExtendedActionGroup ()
216+ public function testGenerateExtendedActionGroup (): void
207217 {
208218 $ mockSimpleActionGroup = [
209219 "nodeName " => "actionGroup " ,
@@ -259,10 +269,12 @@ public function testGenerateExtendedActionGroup()
259269 }
260270
261271 /**
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
264276 */
265- public function testGenerateExtendedActionGroupNoParent ()
277+ public function testGenerateExtendedActionGroupNoParent (): void
266278 {
267279 $ mockExtendedActionGroup = [
268280 "nodeName " => "actionGroup " ,
@@ -292,10 +304,12 @@ public function testGenerateExtendedActionGroupNoParent()
292304 }
293305
294306 /**
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
297311 */
298- public function testExtendingExtendedActionGroup ()
312+ public function testExtendingExtendedActionGroup (): void
299313 {
300314 $ mockParentActionGroup = [
301315 "nodeName " => "actionGroup " ,
@@ -333,7 +347,7 @@ public function testExtendingExtendedActionGroup()
333347 // parse and generate test object with mocked data
334348 try {
335349 ActionGroupObjectHandler::getInstance ()->getObject ('mockExtendedActionGroup ' );
336- } catch (\ Exception $ e ) {
350+ } catch (Exception $ e ) {
337351 // validate log statement
338352 TestLoggingUtil::getInstance ()->validateMockLogStatement (
339353 'error ' ,
@@ -347,11 +361,12 @@ public function testExtendingExtendedActionGroup()
347361 }
348362
349363 /**
350- * Tests generating a test that extends a skipped parent test
364+ * Tests generating a test that extends a skipped parent test.
351365 *
352- * @throws \Exception
366+ * @return void
367+ * @throws Exception
353368 */
354- public function testExtendedTestSkippedParent ()
369+ public function testExtendedTestSkippedParent (): void
355370 {
356371 $ testDataArrayBuilder = new TestDataArrayBuilder ();
357372 $ mockParentTest = $ testDataArrayBuilder
@@ -384,43 +399,55 @@ public function testExtendedTestSkippedParent()
384399 /**
385400 * Function used to set mock for parser return and force init method to run between tests.
386401 *
387- * @param array $testData
388- * @throws \Exception
402+ * @param array|null $testData
403+ * @param array|null $actionGroupData
404+ *
405+ * @return void
406+ * @throws Exception
389407 */
390- private function setMockTestOutput ($ testData = null , $ actionGroupData = null )
408+ private function setMockTestOutput (array $ testData = null , array $ actionGroupData = null ): void
391409 {
392410 // clear test object handler value to inject parsed content
393- $ property = new \ ReflectionProperty (TestObjectHandler::class, 'testObjectHandler ' );
411+ $ property = new ReflectionProperty (TestObjectHandler::class, 'testObjectHandler ' );
394412 $ property ->setAccessible (true );
395413 $ property ->setValue (null );
396414
397415 // clear test object handler value to inject parsed content
398- $ property = new \ ReflectionProperty (ActionGroupObjectHandler::class, 'instance ' );
416+ $ property = new ReflectionProperty (ActionGroupObjectHandler::class, 'instance ' );
399417 $ property ->setAccessible (true );
400418 $ property ->setValue (null );
401419
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 ;
419445 }
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 );
425452 }
426453}
0 commit comments