@@ -113,7 +113,6 @@ function buildProject()
113
113
* @param array $opts
114
114
* @return void
115
115
*/
116
-
117
116
function generateTests (array $ tests , $ opts = [
118
117
'config ' => null ,
119
118
'force ' => false ,
@@ -122,48 +121,87 @@ function generateTests(array $tests, $opts = [
122
121
'tests ' => null
123
122
])
124
123
{
125
- $ GLOBALS ['GENERATE_TESTS ' ] = true ;
126
- $ GLOBALS ['FORCE_PHP_GENERATE ' ] = $ opts ['force ' ];
127
124
require 'tests ' . DIRECTORY_SEPARATOR . 'functional ' . DIRECTORY_SEPARATOR . '_bootstrap.php ' ;
125
+ $ testConfiguration = $ this ->createTestConfiguration ($ tests , $ opts );
128
126
129
- $ testObjects = [];
130
- $ suitesReferences = [ ];
127
+ // maintain backwards compatability for devops
128
+ $ lines = $ opts [ ' lines ' ] ?? $ opts [ ' nodes ' ];
131
129
132
- if ($ opts ['tests ' ] != null ) {
133
- $ testConfigArray = json_decode ($ opts ['tests ' ],true );
134
- $ tests = $ testConfigArray ['tests ' ] ?? [];
135
- $ suitesReferences = $ testConfigArray ['suites ' ] ?? null ;
136
- }
130
+ // create our manifest file here
131
+ $ testManifest = \Magento \FunctionalTestingFramework \Util \Manifest \TestManifestFactory::makeManifest ($ opts ['config ' ],$ testConfiguration ['suites ' ]);
132
+ \Magento \FunctionalTestingFramework \Util \TestGenerator::getInstance (null , $ testConfiguration ['tests ' ])->createAllTestFiles ($ testManifest );
137
133
138
- // stop execution if we have failed to properly parse any json
139
- if (json_last_error () != JSON_ERROR_NONE ) {
140
- $ this ->say ("JSON could not be parsed: " . json_last_error_msg ());
141
- return ;
134
+ if ($ opts ['config ' ] == 'parallel ' ) {
135
+ $ testManifest ->createTestGroups ($ lines );
142
136
}
143
137
144
- if (!empty ($ tests ))
138
+ \Magento \FunctionalTestingFramework \Suite \SuiteGenerator::getInstance ()->generateAllSuites ($ testManifest );
139
+ $ testManifest ->generate ();
140
+
141
+ $ this ->say ("Generate Tests Command Run " );
142
+ }
143
+
144
+
145
+ /**
146
+ * Function which builds up a configuration including test and suites for consumption of Magento generation methods.
147
+ *
148
+ * @param array $tests
149
+ * @param array $opts
150
+ * @return array
151
+ */
152
+ private function createTestConfiguration ($ tests , $ opts )
153
+ {
154
+ // set these globals as we only run this method during generation.
155
+ $ GLOBALS ['GENERATE_TESTS ' ] = true ;
156
+ $ GLOBALS ['FORCE_PHP_GENERATE ' ] = $ opts ['force ' ];
157
+
158
+ $ testConfiguration = [];
159
+ $ testConfiguration ['tests ' ] = $ tests ;
160
+ $ testConfiguration ['suites ' ] = [];
161
+
162
+ $ testConfiguration = $ this ->parseTestsConfigJson ($ opts ['tests ' ], $ testConfiguration );
163
+
164
+ // if we have references to specific tests, we resolve the test objects and pass them to the config
165
+ if (!empty ($ testConfiguration ['tests ' ]))
145
166
{
146
- foreach ($ tests as $ test )
167
+ $ testObjects = [];
168
+
169
+ foreach ($ testConfiguration ['tests ' ] as $ test )
147
170
{
148
171
$ testObjects [$ test ] = Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler::getInstance ()->getObject ($ test );
149
172
}
150
- }
151
173
152
- // maintain backwards compatability for devops
153
- $ lines = $ opts [ ' lines ' ] ?? $ opts [ ' nodes ' ];
174
+ $ testConfiguration [ ' tests ' ] = $ testObjects ;
175
+ }
154
176
155
- // create our manifest file here
156
- $ testManifest = \Magento \FunctionalTestingFramework \Util \Manifest \TestManifestFactory::makeManifest ($ opts ['config ' ],$ suitesReferences );
157
- \Magento \FunctionalTestingFramework \Util \TestGenerator::getInstance (null , $ testObjects )->createAllTestFiles ($ testManifest );
177
+ return $ testConfiguration ;
178
+ }
158
179
159
- if ($ opts ['config ' ] == 'parallel ' ) {
160
- $ testManifest ->createTestGroups ($ lines );
180
+ /**
181
+ * Function which takes a json string of potential custom configuration and parses/validates the resulting json
182
+ * passed in by the user. The result is a testConfiguration array.
183
+ *
184
+ * @param string $json
185
+ * @param array $testConfiguration
186
+ * @return array
187
+ */
188
+ private function parseTestsConfigJson ($ json , $ testConfiguration ) {
189
+ if ($ json == null ) {
190
+ return $ testConfiguration ;
161
191
}
162
192
163
- \ Magento \ FunctionalTestingFramework \ Suite \SuiteGenerator:: getInstance ()-> generateAllSuites ( $ testManifest ) ;
164
- $ testManifest -> generate ( );
193
+ $ jsonTestConfiguration = [] ;
194
+ $ testConfigArray = json_decode ( $ json , true );
165
195
166
- $ this ->say ("Generate Tests Command Run " );
196
+ // stop execution if we have failed to properly parse any json
197
+ if (json_last_error () != JSON_ERROR_NONE ) {
198
+ $ this ->say ("JSON could not be parsed: " . json_last_error_msg ());
199
+ exit (1 );
200
+ }
201
+
202
+ $ jsonTestConfiguration ['tests ' ] = $ testConfigArray ['tests ' ] ?? null ;;
203
+ $ jsonTestConfiguration ['suites ' ] = $ testConfigArray ['suites ' ] ?? null ;
204
+ return $ jsonTestConfiguration ;
167
205
}
168
206
169
207
/**
0 commit comments