3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace tests \unit \Magento \FunctionalTestFramework \Console ;
7
9
8
- use PHPUnit \ Framework \ TestCase ;
10
+ use Exception ;
9
11
use Magento \FunctionalTestingFramework \Console \BaseGenerateCommand ;
10
- use Magento \FunctionalTestingFramework \Suite \Objects \SuiteObject ;
11
12
use Magento \FunctionalTestingFramework \Suite \Handlers \SuiteObjectHandler ;
12
- use Magento \FunctionalTestingFramework \Test \Objects \TestObject ;
13
+ use Magento \FunctionalTestingFramework \Suite \Objects \SuiteObject ;
13
14
use 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 ;
14
20
15
21
class BaseGenerateCommandTest extends TestCase
16
22
{
17
- public function tearDown (): void
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ protected function tearDown (): void
18
27
{
19
28
$ handler = TestObjectHandler::getInstance ();
20
- $ property = new \ReflectionProperty (TestObjectHandler::class, 'tests ' );
21
- $ property ->setAccessible (true );
22
- $ property ->setValue ($ handler , []);
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 );
23
35
24
36
$ handler = SuiteObjectHandler::getInstance ();
25
- $ property = new \ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
26
- $ property ->setAccessible (true );
27
- $ property ->setValue ($ handler , []);
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 );
28
43
}
29
- public function testOneTestOneSuiteConfig ()
44
+
45
+ public function testOneTestOneSuiteConfig (): void
30
46
{
31
47
$ testOne = new TestObject ('Test1 ' , [], [], []);
32
48
$ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -41,7 +57,7 @@ public function testOneTestOneSuiteConfig()
41
57
$ this ->assertEquals ($ expected , $ actual );
42
58
}
43
59
44
- public function testOneTestTwoSuitesConfig ()
60
+ public function testOneTestTwoSuitesConfig (): void
45
61
{
46
62
$ testOne = new TestObject ('Test1 ' , [], [], []);
47
63
$ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -57,7 +73,7 @@ public function testOneTestTwoSuitesConfig()
57
73
$ this ->assertEquals ($ expected , $ actual );
58
74
}
59
75
60
- public function testOneTestOneGroup ()
76
+ public function testOneTestOneGroup (): void
61
77
{
62
78
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
63
79
@@ -71,7 +87,7 @@ public function testOneTestOneGroup()
71
87
$ this ->assertEquals ($ expected , $ actual );
72
88
}
73
89
74
- public function testThreeTestsTwoGroup ()
90
+ public function testThreeTestsTwoGroup (): void
75
91
{
76
92
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
77
93
$ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group1 ' ]], []);
@@ -87,7 +103,7 @@ public function testThreeTestsTwoGroup()
87
103
$ this ->assertEquals ($ expected , $ actual );
88
104
}
89
105
90
- public function testOneTestOneSuiteOneGroupConfig ()
106
+ public function testOneTestOneSuiteOneGroupConfig (): void
91
107
{
92
108
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
93
109
$ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -102,7 +118,7 @@ public function testOneTestOneSuiteOneGroupConfig()
102
118
$ this ->assertEquals ($ expected , $ actual );
103
119
}
104
120
105
- public function testTwoTestOneSuiteTwoGroupConfig ()
121
+ public function testTwoTestOneSuiteTwoGroupConfig (): void
106
122
{
107
123
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
108
124
$ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group2 ' ]], []);
@@ -118,7 +134,7 @@ public function testTwoTestOneSuiteTwoGroupConfig()
118
134
$ this ->assertEquals ($ expected , $ actual );
119
135
}
120
136
121
- public function testTwoTestTwoSuiteOneGroupConfig ()
137
+ public function testTwoTestTwoSuiteOneGroupConfig (): void
122
138
{
123
139
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
124
140
$ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group1 ' ]], []);
@@ -137,10 +153,12 @@ public function testTwoTestTwoSuiteOneGroupConfig()
137
153
138
154
/**
139
155
* Test specific usecase of a test that is in a group with the group being called along with the suite
140
- * i.e. run:group Group1 Suite1
141
- * @throws \Exception
156
+ * i.e. run:group Group1 Suite1.
157
+ *
158
+ * @return void
159
+ * @throws Exception
142
160
*/
143
- public function testThreeTestOneSuiteOneGroupMix ()
161
+ public function testThreeTestOneSuiteOneGroupMix (): void
144
162
{
145
163
$ testOne = new TestObject ('Test1 ' , [], [], []);
146
164
$ testTwo = new TestObject ('Test2 ' , [], [], []);
@@ -162,7 +180,7 @@ public function testThreeTestOneSuiteOneGroupMix()
162
180
$ this ->assertEquals ($ expected , $ actual );
163
181
}
164
182
165
- public function testSuiteToTestSyntax ()
183
+ public function testSuiteToTestSyntax (): void
166
184
{
167
185
$ testOne = new TestObject ('Test1 ' , [], [], []);
168
186
$ suiteOne = new SuiteObject (
@@ -181,49 +199,82 @@ public function testSuiteToTestSyntax()
181
199
}
182
200
183
201
/**
184
- * Mock handlers to skip parsing
202
+ * Mock handlers to skip parsing.
203
+ *
185
204
* @param array $testArray
186
205
* @param array $suiteArray
187
- * @throws \Exception
206
+ *
207
+ * @return void
208
+ * @throws Exception
188
209
*/
189
- public function mockHandlers ($ testArray , $ suiteArray )
210
+ public function mockHandlers (array $ testArray , array $ suiteArray ): void
190
211
{
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
+
191
223
$ handler = TestObjectHandler::getInstance ();
192
- $ property = new \ ReflectionProperty (TestObjectHandler::class, 'tests ' );
224
+ $ property = new ReflectionProperty (TestObjectHandler::class, 'tests ' );
193
225
$ property ->setAccessible (true );
194
226
$ property ->setValue ($ handler , $ testArray );
195
227
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
+
196
239
$ handler = SuiteObjectHandler::getInstance ();
197
- $ property = new \ ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
240
+ $ property = new ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
198
241
$ property ->setAccessible (true );
199
242
$ property ->setValue ($ handler , $ suiteArray );
200
243
}
201
244
202
245
/**
203
- * Changes visibility and runs getTestAndSuiteConfiguration
246
+ * Changes visibility and runs getTestAndSuiteConfiguration.
247
+ *
204
248
* @param array $testArray
249
+ *
205
250
* @return string
251
+ * @throws ReflectionException
206
252
*/
207
- public function callTestConfig ($ testArray )
253
+ public function callTestConfig (array $ testArray ): string
208
254
{
209
255
$ command = new BaseGenerateCommand ();
210
- $ class = new \ ReflectionClass ($ command );
256
+ $ class = new ReflectionClass ($ command );
211
257
$ method = $ class ->getMethod ('getTestAndSuiteConfiguration ' );
212
258
$ method ->setAccessible (true );
259
+
213
260
return $ method ->invokeArgs ($ command , [$ testArray ]);
214
261
}
215
262
216
263
/**
217
- * Changes visibility and runs getGroupAndSuiteConfiguration
264
+ * Changes visibility and runs getGroupAndSuiteConfiguration.
265
+ *
218
266
* @param array $groupArray
267
+ *
219
268
* @return string
269
+ * @throws ReflectionException
220
270
*/
221
- public function callGroupConfig ($ groupArray )
271
+ public function callGroupConfig (array $ groupArray ): string
222
272
{
223
273
$ command = new BaseGenerateCommand ();
224
- $ class = new \ ReflectionClass ($ command );
274
+ $ class = new ReflectionClass ($ command );
225
275
$ method = $ class ->getMethod ('getGroupAndSuiteConfiguration ' );
226
276
$ method ->setAccessible (true );
277
+
227
278
return $ method ->invokeArgs ($ command , [$ groupArray ]);
228
279
}
229
280
}
0 commit comments