-
Notifications
You must be signed in to change notification settings - Fork 132
MQE-1703: Implicit Suite Generation for Tests #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
315616f
5ba993a
3282770
79ff347
1a2dc67
4bbfb25
da509f2
f353afe
4a519fe
5f81deb
4720af5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil; | ||
use Magento\FunctionalTestingFramework\Util\TestGenerator; | ||
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; | ||
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler; | ||
|
||
class BaseGenerateCommand extends Command | ||
{ | ||
|
@@ -67,4 +68,40 @@ protected function removeGeneratedDirectory(OutputInterface $output, bool $verbo | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns an array of test configuration to be used as an argument for generation of tests | ||
* @param array $tests | ||
* @return false|string | ||
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException | ||
*/ | ||
|
||
protected function getTestAndSuiteConfiguration(array $tests) | ||
{ | ||
$testConfiguration['tests'] = null; | ||
$testConfiguration['suites'] = null; | ||
$testsReferencedInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); | ||
$resolvedTests = []; | ||
|
||
foreach($tests as $test) { | ||
if (array_key_exists($test, $testsReferencedInSuites)) { | ||
$suites = $testsReferencedInSuites[$test]; | ||
$resolvedTests = array_merge( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change this array_merge/map combo to something a little more simple?
array_map/merge are both recursive loops at the language level (at least I know map is) so this alternative is either equal or actually faster (easier to read in either case) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was trying to avoid nested loops as I didn't find many implementations of it in code, thought it was a style thing. Changed it. |
||
$resolvedTests, | ||
array_map(function ($value) use ($test) { | ||
return $value . ':' . $test; | ||
}, $suites) | ||
); | ||
} | ||
// configuration for tests | ||
else $testConfiguration['tests'][] = $test; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to use multiline else formatting:
|
||
} | ||
// configuration for suites | ||
foreach ($resolvedTests as $test) { | ||
list($suite, $test) = explode(":", $test); | ||
$testConfiguration['suites'][$suite][] = $test; | ||
} | ||
$testConfigurationJson = json_encode($testConfiguration); | ||
return $testConfigurationJson; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,28 +63,35 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
); | ||
} | ||
|
||
$testConfiguration = $this->getTestAndSuiteConfiguration($tests); | ||
|
||
if (!$skipGeneration) { | ||
$command = $this->getApplication()->find('generate:tests'); | ||
$args = [ | ||
'--tests' => json_encode([ | ||
'tests' => $tests, | ||
'suites' => null | ||
]), | ||
'--tests' => $testConfiguration, | ||
'--force' => $force, | ||
'--remove' => $remove, | ||
'--debug' => $debug, | ||
'--allowSkipped' => $allowSkipped | ||
]; | ||
$command->run(new ArrayInput($args), $output); | ||
} | ||
// tests with resolved suite references | ||
$resolvedTests = $this->resolveSuiteReferences($testConfiguration); | ||
|
||
$returnCode = 0; | ||
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional '; | ||
$testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR; | ||
$returnCode = 0; | ||
//execute only tests specified as arguments in run command | ||
foreach ($tests as $test) { | ||
$testGroup = TestGenerator::DEFAULT_DIR . DIRECTORY_SEPARATOR; | ||
$testName = $test . 'Cest.php'; | ||
foreach ($resolvedTests as $test) { | ||
//set directory as suite name for tests in suite, if not set to "default" | ||
if (strpos($test, ':')) { | ||
list($testGroup, $testName) = explode(":", $test); | ||
} else { | ||
list($testGroup, $testName) = [TestGenerator::DEFAULT_DIR, $test]; | ||
} | ||
$testGroup = $testGroup . DIRECTORY_SEPARATOR; | ||
$testName = $testName . 'Cest.php'; | ||
if (!realpath($testsDirectory . $testGroup . $testName)) { | ||
throw new TestFrameworkException( | ||
$testName . " is not available under " . $testsDirectory . $testGroup | ||
|
@@ -104,4 +111,27 @@ function ($type, $buffer) use ($output) { | |
} | ||
return $returnCode; | ||
} | ||
|
||
/** Get an array of tests with resolved suite references from $testConfiguration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top of docblock needs empty line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
* eg: if test is referenced in a suite, it'll be stored in format suite:test | ||
* @param string $testConfigurationJson | ||
* @return array | ||
*/ | ||
private function resolveSuiteReferences($testConfigurationJson) | ||
{ | ||
$testConfiguration = json_decode($testConfigurationJson, true); | ||
$testsArray = $testConfiguration['tests'] ?? []; | ||
$suitesArray = $testConfiguration['suites'] ?? []; | ||
$testArrayBuilder = []; | ||
|
||
foreach ($suitesArray as $suite => $tests) { | ||
$testArrayBuilder = array_merge( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See commend in BaseGenerateCommand, this can probably be simplified into one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||
$testArrayBuilder, | ||
array_map(function ($test) use ($suite) { | ||
return $suite . ':' . $test; | ||
}, $tests) | ||
); | ||
} | ||
return array_merge($testArrayBuilder, $testsArray); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor but rename this to
$suiteToTestPair
, I thought at first this would hold either type of test but it only holds suite:test pairsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed.