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 \Util ;
89
9- use AspectMock \ Test as AspectMock ;
10-
10+ use Exception ;
11+ use Magento \ FunctionalTestingFramework \ Exceptions \ TestReferenceException ;
1112use Magento \FunctionalTestingFramework \Filter \FilterList ;
12- use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
1313use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
1414use Magento \FunctionalTestingFramework \Test \Objects \TestHookObject ;
1515use Magento \FunctionalTestingFramework \Test \Objects \TestObject ;
16+ use Magento \FunctionalTestingFramework \Util \Filesystem \CestFileCreatorUtil ;
17+ use ReflectionProperty ;
1618use tests \unit \Util \MagentoTestCase ;
1719use Magento \FunctionalTestingFramework \Util \TestGenerator ;
1820use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
2224class TestGeneratorTest extends MagentoTestCase
2325{
2426 /**
25- * Before method functionality
27+ * Before method functionality.
2628 */
2729 public function setUp (): void
2830 {
2931 TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
3032 }
3133
3234 /**
33- * After method functionality
35+ * After method functionality.
3436 *
3537 * @return void
3638 */
3739 public function tearDown (): void
3840 {
39- AspectMock::clean ();
4041 GenerationErrorHandler::getInstance ()->reset ();
4142 }
4243
4344 /**
4445 * Basic test to check exceptions for incorrect entities.
4546 *
46- * @throws \Exception
47+ * @return void
48+ * @throws Exception
4749 */
48- public function testEntityException ()
50+ public function testEntityException (): void
4951 {
5052 $ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
5153 'userInput ' => '{{someEntity.entity}} '
5254 ]);
5355
5456 $ testObject = new TestObject ("sampleTest " , ["merge123 " => $ actionObject ], [], [], "filename " );
55-
56- AspectMock::double (TestObjectHandler::class, ['initTestData ' => '' ]);
57-
5857 $ testGeneratorObject = TestGenerator::getInstance ("" , ["sampleTest " => $ testObject ]);
59-
60- AspectMock::double (TestGenerator::class, ['loadAllTestObjects ' => ["sampleTest " => $ testObject ]]);
61-
6258 $ testGeneratorObject ->createAllTestFiles (null , []);
6359
6460 // assert that no exception for createAllTestFiles and generation error is stored in GenerationErrorHandler
@@ -69,11 +65,12 @@ public function testEntityException()
6965 }
7066
7167 /**
72- * Tests that skipped tests do not have a fully generated body
68+ * Tests that skipped tests do not have a fully generated body.
7369 *
74- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
70+ * @return void
71+ * @throws TestReferenceException
7572 */
76- public function testSkippedNoGeneration ()
73+ public function testSkippedNoGeneration (): void
7774 {
7875 $ actionInput = 'fakeInput ' ;
7976 $ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
@@ -91,14 +88,22 @@ public function testSkippedNoGeneration()
9188 }
9289
9390 /**
94- * Tests that skipped tests have a fully generated body when --allowSkipped is passed in
91+ * Tests that skipped tests have a fully generated body when --allowSkipped is passed in.
9592 *
96- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
93+ * @return void
94+ * @throws TestReferenceException
9795 */
98- public function testAllowSkipped ()
96+ public function testAllowSkipped (): void
9997 {
10098 // Mock allowSkipped for TestGenerator
101- AspectMock::double (MftfApplicationConfig::class, ['allowSkipped ' => true ]);
99+ $ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
100+ $ mockConfig ->expects ($ this ->any ())
101+ ->method ('allowSkipped ' )
102+ ->willReturn (true );
103+
104+ $ property = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
105+ $ property ->setAccessible (true );
106+ $ property ->setValue ($ mockConfig );
102107
103108 $ actionInput = 'fakeInput ' ;
104109 $ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
@@ -128,17 +133,20 @@ public function testAllowSkipped()
128133 }
129134
130135 /**
131- * Tests that TestGenerator createAllTestFiles correctly filters based on severity
136+ * Tests that TestGenerator createAllTestFiles correctly filters based on severity.
132137 *
133- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
138+ * @return void
139+ * @throws TestReferenceException
134140 */
135- public function testFilter ()
141+ public function testFilter (): void
136142 {
137- // Mock filters for TestGenerator
138- AspectMock::double (
139- MftfApplicationConfig::class,
140- ['getFilterList ' => new FilterList (['severity ' => ["CRITICAL " ]])]
141- );
143+ $ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
144+ $ fileList = new FilterList (['severity ' => ["CRITICAL " ]]);
145+ $ mockConfig ->expects ($ this ->once ())->method ('getFilterList ' )->willReturn ($ fileList );
146+
147+ $ property = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
148+ $ property ->setAccessible (true );
149+ $ property ->setValue ($ mockConfig );
142150
143151 $ actionInput = 'fakeInput ' ;
144152 $ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
@@ -161,16 +169,26 @@ public function testFilter()
161169 [],
162170 "filename "
163171 );
164- AspectMock::double (TestGenerator::class, ['loadAllTestObjects ' => ["sampleTest " => $ test1 , "test2 " => $ test2 ]]);
165172
166173 // Mock createCestFile to return name of tests that testGenerator tried to create
167174 $ generatedTests = [];
168- AspectMock::double (TestGenerator::class, ['createCestFile ' => function ($ arg1 , $ arg2 ) use (&$ generatedTests ) {
169- $ generatedTests [$ arg2 ] = true ;
170- }]);
175+ $ cestFileCreatorUtil = $ this ->createMock (CestFileCreatorUtil::class);
176+ $ cestFileCreatorUtil ->expects ($ this ->once ())
177+ ->method ('create ' )
178+ ->will (
179+ $ this ->returnCallback (
180+ function ($ filename ) use (&$ generatedTests ) {
181+ $ generatedTests [$ filename ] = true ;
182+ }
183+ )
184+ );
185+
186+ $ property = new ReflectionProperty (CestFileCreatorUtil::class, 'INSTANCE ' );
187+ $ property ->setAccessible (true );
188+ $ property ->setValue ($ cestFileCreatorUtil );
171189
172190 $ testGeneratorObject = TestGenerator::getInstance ("" , ["sampleTest " => $ test1 , "test2 " => $ test2 ]);
173- $ testGeneratorObject ->createAllTestFiles (null , [] );
191+ $ testGeneratorObject ->createAllTestFiles ();
174192
175193 // Ensure Test1 was Generated but not Test 2
176194 $ this ->assertArrayHasKey ('test1Cest ' , $ generatedTests );
0 commit comments