33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace tests \unit \Magento \FunctionalTestFramework \Console ;
79
8- use AspectMock \Test as AspectMock ;
9- use PHPUnit \Framework \TestCase ;
10+ use Exception ;
1011use Magento \FunctionalTestingFramework \Console \BaseGenerateCommand ;
11- use Magento \FunctionalTestingFramework \Suite \Objects \SuiteObject ;
1212use Magento \FunctionalTestingFramework \Suite \Handlers \SuiteObjectHandler ;
13- use Magento \FunctionalTestingFramework \Test \Objects \TestObject ;
13+ use Magento \FunctionalTestingFramework \Suite \Objects \SuiteObject ;
1414use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
15+ use Magento \FunctionalTestingFramework \Test \Objects \TestObject ;
16+ use PHPUnit \Framework \TestCase ;
17+ use ReflectionClass ;
18+ use ReflectionException ;
19+ use ReflectionProperty ;
1520
1621class BaseGenerateCommandTest extends TestCase
1722{
18- public function tearDown (): void
23+ /**
24+ * @inheritDoc
25+ */
26+ protected function tearDown (): void
1927 {
20- AspectMock::clean ();
28+ $ handler = TestObjectHandler::getInstance ();
29+ $ testsProperty = new ReflectionProperty (TestObjectHandler::class, 'tests ' );
30+ $ testsProperty ->setAccessible (true );
31+ $ testsProperty ->setValue ($ handler , []);
32+ $ testObjectHandlerProperty = new ReflectionProperty (TestObjectHandler::class, 'testObjectHandler ' );
33+ $ testObjectHandlerProperty ->setAccessible (true );
34+ $ testObjectHandlerProperty ->setValue ($ handler );
35+
36+ $ handler = SuiteObjectHandler::getInstance ();
37+ $ suiteObjectsProperty = new ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
38+ $ suiteObjectsProperty ->setAccessible (true );
39+ $ suiteObjectsProperty ->setValue ($ handler , []);
40+ $ suiteObjectHandlerProperty = new ReflectionProperty (SuiteObjectHandler::class, 'instance ' );
41+ $ suiteObjectHandlerProperty ->setAccessible (true );
42+ $ suiteObjectHandlerProperty ->setValue ($ handler );
2143 }
2244
23- public function testOneTestOneSuiteConfig ()
45+ public function testOneTestOneSuiteConfig (): void
2446 {
2547 $ testOne = new TestObject ('Test1 ' , [], [], []);
2648 $ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -35,7 +57,7 @@ public function testOneTestOneSuiteConfig()
3557 $ this ->assertEquals ($ expected , $ actual );
3658 }
3759
38- public function testOneTestTwoSuitesConfig ()
60+ public function testOneTestTwoSuitesConfig (): void
3961 {
4062 $ testOne = new TestObject ('Test1 ' , [], [], []);
4163 $ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -51,7 +73,7 @@ public function testOneTestTwoSuitesConfig()
5173 $ this ->assertEquals ($ expected , $ actual );
5274 }
5375
54- public function testOneTestOneGroup ()
76+ public function testOneTestOneGroup (): void
5577 {
5678 $ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
5779
@@ -65,7 +87,7 @@ public function testOneTestOneGroup()
6587 $ this ->assertEquals ($ expected , $ actual );
6688 }
6789
68- public function testThreeTestsTwoGroup ()
90+ public function testThreeTestsTwoGroup (): void
6991 {
7092 $ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
7193 $ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group1 ' ]], []);
@@ -81,7 +103,7 @@ public function testThreeTestsTwoGroup()
81103 $ this ->assertEquals ($ expected , $ actual );
82104 }
83105
84- public function testOneTestOneSuiteOneGroupConfig ()
106+ public function testOneTestOneSuiteOneGroupConfig (): void
85107 {
86108 $ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
87109 $ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -96,7 +118,7 @@ public function testOneTestOneSuiteOneGroupConfig()
96118 $ this ->assertEquals ($ expected , $ actual );
97119 }
98120
99- public function testTwoTestOneSuiteTwoGroupConfig ()
121+ public function testTwoTestOneSuiteTwoGroupConfig (): void
100122 {
101123 $ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
102124 $ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group2 ' ]], []);
@@ -112,7 +134,7 @@ public function testTwoTestOneSuiteTwoGroupConfig()
112134 $ this ->assertEquals ($ expected , $ actual );
113135 }
114136
115- public function testTwoTestTwoSuiteOneGroupConfig ()
137+ public function testTwoTestTwoSuiteOneGroupConfig (): void
116138 {
117139 $ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
118140 $ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group1 ' ]], []);
@@ -131,10 +153,12 @@ public function testTwoTestTwoSuiteOneGroupConfig()
131153
132154 /**
133155 * Test specific usecase of a test that is in a group with the group being called along with the suite
134- * i.e. run:group Group1 Suite1
135- * @throws \Exception
156+ * i.e. run:group Group1 Suite1.
157+ *
158+ * @return void
159+ * @throws Exception
136160 */
137- public function testThreeTestOneSuiteOneGroupMix ()
161+ public function testThreeTestOneSuiteOneGroupMix (): void
138162 {
139163 $ testOne = new TestObject ('Test1 ' , [], [], []);
140164 $ testTwo = new TestObject ('Test2 ' , [], [], []);
@@ -156,7 +180,7 @@ public function testThreeTestOneSuiteOneGroupMix()
156180 $ this ->assertEquals ($ expected , $ actual );
157181 }
158182
159- public function testSuiteToTestSyntax ()
183+ public function testSuiteToTestSyntax (): void
160184 {
161185 $ testOne = new TestObject ('Test1 ' , [], [], []);
162186 $ suiteOne = new SuiteObject (
@@ -175,51 +199,82 @@ public function testSuiteToTestSyntax()
175199 }
176200
177201 /**
178- * Mock handlers to skip parsing
202+ * Mock handlers to skip parsing.
203+ *
179204 * @param array $testArray
180205 * @param array $suiteArray
181- * @throws \Exception
206+ *
207+ * @return void
208+ * @throws Exception
182209 */
183- public function mockHandlers ($ testArray , $ suiteArray )
210+ public function mockHandlers (array $ testArray , array $ suiteArray ): void
184211 {
185- AspectMock::double (TestObjectHandler::class, ['initTestData ' => '' ])->make ();
212+ // bypass the initTestData method
213+ $ testObjectHandlerClass = new ReflectionClass (TestObjectHandler::class);
214+ $ constructor = $ testObjectHandlerClass ->getConstructor ();
215+ $ constructor ->setAccessible (true );
216+ $ testObjectHandlerObject = $ testObjectHandlerClass ->newInstanceWithoutConstructor ();
217+ $ constructor ->invoke ($ testObjectHandlerObject );
218+
219+ $ testObjectHandlerProperty = new ReflectionProperty (TestObjectHandler::class, 'testObjectHandler ' );
220+ $ testObjectHandlerProperty ->setAccessible (true );
221+ $ testObjectHandlerProperty ->setValue ($ testObjectHandlerObject );
222+
186223 $ handler = TestObjectHandler::getInstance ();
187- $ property = new \ ReflectionProperty (TestObjectHandler::class, 'tests ' );
224+ $ property = new ReflectionProperty (TestObjectHandler::class, 'tests ' );
188225 $ property ->setAccessible (true );
189226 $ property ->setValue ($ handler , $ testArray );
190227
191- AspectMock::double (SuiteObjectHandler::class, ['initSuiteData ' => '' ])->make ();
228+ // bypass the initTestData method
229+ $ suiteObjectHandlerClass = new ReflectionClass (SuiteObjectHandler::class);
230+ $ constructor = $ suiteObjectHandlerClass ->getConstructor ();
231+ $ constructor ->setAccessible (true );
232+ $ suiteObjectHandlerObject = $ suiteObjectHandlerClass ->newInstanceWithoutConstructor ();
233+ $ constructor ->invoke ($ suiteObjectHandlerObject );
234+
235+ $ suiteObjectHandlerProperty = new ReflectionProperty (SuiteObjectHandler::class, 'instance ' );
236+ $ suiteObjectHandlerProperty ->setAccessible (true );
237+ $ suiteObjectHandlerProperty ->setValue ($ suiteObjectHandlerObject );
238+
192239 $ handler = SuiteObjectHandler::getInstance ();
193- $ property = new \ ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
240+ $ property = new ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
194241 $ property ->setAccessible (true );
195242 $ property ->setValue ($ handler , $ suiteArray );
196243 }
197244
198245 /**
199- * Changes visibility and runs getTestAndSuiteConfiguration
246+ * Changes visibility and runs getTestAndSuiteConfiguration.
247+ *
200248 * @param array $testArray
249+ *
201250 * @return string
251+ * @throws ReflectionException
202252 */
203- public function callTestConfig ($ testArray )
253+ public function callTestConfig (array $ testArray ): string
204254 {
205255 $ command = new BaseGenerateCommand ();
206- $ class = new \ ReflectionClass ($ command );
256+ $ class = new ReflectionClass ($ command );
207257 $ method = $ class ->getMethod ('getTestAndSuiteConfiguration ' );
208258 $ method ->setAccessible (true );
259+
209260 return $ method ->invokeArgs ($ command , [$ testArray ]);
210261 }
211262
212263 /**
213- * Changes visibility and runs getGroupAndSuiteConfiguration
264+ * Changes visibility and runs getGroupAndSuiteConfiguration.
265+ *
214266 * @param array $groupArray
267+ *
215268 * @return string
269+ * @throws ReflectionException
216270 */
217- public function callGroupConfig ($ groupArray )
271+ public function callGroupConfig (array $ groupArray ): string
218272 {
219273 $ command = new BaseGenerateCommand ();
220- $ class = new \ ReflectionClass ($ command );
274+ $ class = new ReflectionClass ($ command );
221275 $ method = $ class ->getMethod ('getGroupAndSuiteConfiguration ' );
222276 $ method ->setAccessible (true );
277+
223278 return $ method ->invokeArgs ($ command , [$ groupArray ]);
224279 }
225280}
0 commit comments