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 AspectMock \Test as AspectMock ;
9
- use PHPUnit \Framework \TestCase ;
10
+ use Exception ;
10
11
use Magento \FunctionalTestingFramework \Console \BaseGenerateCommand ;
11
- use Magento \FunctionalTestingFramework \Suite \Objects \SuiteObject ;
12
12
use Magento \FunctionalTestingFramework \Suite \Handlers \SuiteObjectHandler ;
13
- use Magento \FunctionalTestingFramework \Test \Objects \TestObject ;
13
+ use Magento \FunctionalTestingFramework \Suite \Objects \SuiteObject ;
14
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 ;
15
20
16
21
class BaseGenerateCommandTest extends TestCase
17
22
{
18
- public function tearDown (): void
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ protected function tearDown (): void
19
27
{
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 );
21
43
}
22
44
23
- public function testOneTestOneSuiteConfig ()
45
+ public function testOneTestOneSuiteConfig (): void
24
46
{
25
47
$ testOne = new TestObject ('Test1 ' , [], [], []);
26
48
$ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -35,7 +57,7 @@ public function testOneTestOneSuiteConfig()
35
57
$ this ->assertEquals ($ expected , $ actual );
36
58
}
37
59
38
- public function testOneTestTwoSuitesConfig ()
60
+ public function testOneTestTwoSuitesConfig (): void
39
61
{
40
62
$ testOne = new TestObject ('Test1 ' , [], [], []);
41
63
$ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -51,7 +73,7 @@ public function testOneTestTwoSuitesConfig()
51
73
$ this ->assertEquals ($ expected , $ actual );
52
74
}
53
75
54
- public function testOneTestOneGroup ()
76
+ public function testOneTestOneGroup (): void
55
77
{
56
78
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
57
79
@@ -65,7 +87,7 @@ public function testOneTestOneGroup()
65
87
$ this ->assertEquals ($ expected , $ actual );
66
88
}
67
89
68
- public function testThreeTestsTwoGroup ()
90
+ public function testThreeTestsTwoGroup (): void
69
91
{
70
92
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
71
93
$ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group1 ' ]], []);
@@ -81,7 +103,7 @@ public function testThreeTestsTwoGroup()
81
103
$ this ->assertEquals ($ expected , $ actual );
82
104
}
83
105
84
- public function testOneTestOneSuiteOneGroupConfig ()
106
+ public function testOneTestOneSuiteOneGroupConfig (): void
85
107
{
86
108
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
87
109
$ suiteOne = new SuiteObject ('Suite1 ' , ['Test1 ' => $ testOne ], [], []);
@@ -96,7 +118,7 @@ public function testOneTestOneSuiteOneGroupConfig()
96
118
$ this ->assertEquals ($ expected , $ actual );
97
119
}
98
120
99
- public function testTwoTestOneSuiteTwoGroupConfig ()
121
+ public function testTwoTestOneSuiteTwoGroupConfig (): void
100
122
{
101
123
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
102
124
$ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group2 ' ]], []);
@@ -112,7 +134,7 @@ public function testTwoTestOneSuiteTwoGroupConfig()
112
134
$ this ->assertEquals ($ expected , $ actual );
113
135
}
114
136
115
- public function testTwoTestTwoSuiteOneGroupConfig ()
137
+ public function testTwoTestTwoSuiteOneGroupConfig (): void
116
138
{
117
139
$ testOne = new TestObject ('Test1 ' , [], ['group ' => ['Group1 ' ]], []);
118
140
$ testTwo = new TestObject ('Test2 ' , [], ['group ' => ['Group1 ' ]], []);
@@ -131,10 +153,12 @@ public function testTwoTestTwoSuiteOneGroupConfig()
131
153
132
154
/**
133
155
* 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
136
160
*/
137
- public function testThreeTestOneSuiteOneGroupMix ()
161
+ public function testThreeTestOneSuiteOneGroupMix (): void
138
162
{
139
163
$ testOne = new TestObject ('Test1 ' , [], [], []);
140
164
$ testTwo = new TestObject ('Test2 ' , [], [], []);
@@ -156,7 +180,7 @@ public function testThreeTestOneSuiteOneGroupMix()
156
180
$ this ->assertEquals ($ expected , $ actual );
157
181
}
158
182
159
- public function testSuiteToTestSyntax ()
183
+ public function testSuiteToTestSyntax (): void
160
184
{
161
185
$ testOne = new TestObject ('Test1 ' , [], [], []);
162
186
$ suiteOne = new SuiteObject (
@@ -175,51 +199,82 @@ public function testSuiteToTestSyntax()
175
199
}
176
200
177
201
/**
178
- * Mock handlers to skip parsing
202
+ * Mock handlers to skip parsing.
203
+ *
179
204
* @param array $testArray
180
205
* @param array $suiteArray
181
- * @throws \Exception
206
+ *
207
+ * @return void
208
+ * @throws Exception
182
209
*/
183
- public function mockHandlers ($ testArray , $ suiteArray )
210
+ public function mockHandlers (array $ testArray , array $ suiteArray ): void
184
211
{
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
+
186
223
$ handler = TestObjectHandler::getInstance ();
187
- $ property = new \ ReflectionProperty (TestObjectHandler::class, 'tests ' );
224
+ $ property = new ReflectionProperty (TestObjectHandler::class, 'tests ' );
188
225
$ property ->setAccessible (true );
189
226
$ property ->setValue ($ handler , $ testArray );
190
227
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
+
192
239
$ handler = SuiteObjectHandler::getInstance ();
193
- $ property = new \ ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
240
+ $ property = new ReflectionProperty (SuiteObjectHandler::class, 'suiteObjects ' );
194
241
$ property ->setAccessible (true );
195
242
$ property ->setValue ($ handler , $ suiteArray );
196
243
}
197
244
198
245
/**
199
- * Changes visibility and runs getTestAndSuiteConfiguration
246
+ * Changes visibility and runs getTestAndSuiteConfiguration.
247
+ *
200
248
* @param array $testArray
249
+ *
201
250
* @return string
251
+ * @throws ReflectionException
202
252
*/
203
- public function callTestConfig ($ testArray )
253
+ public function callTestConfig (array $ testArray ): string
204
254
{
205
255
$ command = new BaseGenerateCommand ();
206
- $ class = new \ ReflectionClass ($ command );
256
+ $ class = new ReflectionClass ($ command );
207
257
$ method = $ class ->getMethod ('getTestAndSuiteConfiguration ' );
208
258
$ method ->setAccessible (true );
259
+
209
260
return $ method ->invokeArgs ($ command , [$ testArray ]);
210
261
}
211
262
212
263
/**
213
- * Changes visibility and runs getGroupAndSuiteConfiguration
264
+ * Changes visibility and runs getGroupAndSuiteConfiguration.
265
+ *
214
266
* @param array $groupArray
267
+ *
215
268
* @return string
269
+ * @throws ReflectionException
216
270
*/
217
- public function callGroupConfig ($ groupArray )
271
+ public function callGroupConfig (array $ groupArray ): string
218
272
{
219
273
$ command = new BaseGenerateCommand ();
220
- $ class = new \ ReflectionClass ($ command );
274
+ $ class = new ReflectionClass ($ command );
221
275
$ method = $ class ->getMethod ('getGroupAndSuiteConfiguration ' );
222
276
$ method ->setAccessible (true );
277
+
223
278
return $ method ->invokeArgs ($ command , [$ groupArray ]);
224
279
}
225
280
}
0 commit comments