Skip to content

Commit eb548ae

Browse files
committed
MQE-893: Add flag to robo generate: tests which accepts a specific set of tests to execute
- refactor config to exclude/include suites and tests based on user pref
1 parent 2fba9f6 commit eb548ae

File tree

2 files changed

+69
-30
lines changed

2 files changed

+69
-30
lines changed

dev/tests/acceptance/RoboFile.php

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ function buildProject()
113113
* @param array $opts
114114
* @return void
115115
*/
116-
117116
function generateTests(array $tests, $opts = [
118117
'config' => null,
119118
'force' => false,
@@ -122,48 +121,87 @@ function generateTests(array $tests, $opts = [
122121
'tests' => null
123122
])
124123
{
125-
$GLOBALS['GENERATE_TESTS'] = true;
126-
$GLOBALS['FORCE_PHP_GENERATE'] = $opts['force'];
127124
require 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php';
125+
$testConfiguration = $this->createTestConfiguration($tests, $opts);
128126

129-
$testObjects = [];
130-
$suitesReferences = [];
127+
// maintain backwards compatability for devops
128+
$lines = $opts['lines'] ?? $opts ['nodes'];
131129

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);
137133

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);
142136
}
143137

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']))
145166
{
146-
foreach ($tests as $test)
167+
$testObjects = [];
168+
169+
foreach ($testConfiguration['tests'] as $test)
147170
{
148171
$testObjects[$test] = Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler::getInstance()->getObject($test);
149172
}
150-
}
151173

152-
// maintain backwards compatability for devops
153-
$lines = $opts['lines'] ?? $opts ['nodes'];
174+
$testConfiguration['tests'] = $testObjects;
175+
}
154176

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+
}
158179

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;
161191
}
162192

163-
\Magento\FunctionalTestingFramework\Suite\SuiteGenerator::getInstance()->generateAllSuites($testManifest);
164-
$testManifest->generate();
193+
$jsonTestConfiguration = [];
194+
$testConfigArray = json_decode($json, true);
165195

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;
167205
}
168206

169207
/**

dev/tests/acceptance/tests/_bootstrap.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757

5858
$RELATIVE_TESTS_MODULE_PATH = '/Magento/FunctionalTest';
5959

60-
defined('FW_BP') || define('FW_BP', realpath($FW_PATH));
61-
defined('TESTS_BP') || define('TESTS_BP', realpath($TEST_PATH));
62-
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath($TEST_PATH . $RELATIVE_TESTS_MODULE_PATH));
6360
defined('MAGENTO_BP') || define('MAGENTO_BP', realpath($MAGENTO_PATH));
6461

6562
//Load constants from .env file
@@ -82,6 +79,10 @@
8279
$env->setEnvironmentVariable('MAGENTO_CLI_COMMAND_PARAMETER', MAGENTO_CLI_COMMAND_PARAMETER);
8380
}
8481

82+
defined('FW_BP') || define('FW_BP', realpath($FW_PATH));
83+
defined('TESTS_BP') || define('TESTS_BP', realpath($TEST_PATH));
84+
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath($TEST_PATH . $RELATIVE_TESTS_MODULE_PATH));
85+
8586
// add the debug flag here
8687
$debug_mode = $_ENV['MFTF_DEBUG'] ?? false;
8788
if (!(bool)$debug_mode && extension_loaded('xdebug')) {

0 commit comments

Comments
 (0)