Skip to content

Commit 4bbfb25

Browse files
committed
MQE-1703: Implicit Suite Generation for Tests
fixing unit tests
1 parent 1a2dc67 commit 4bbfb25

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ protected function getTestAndSuiteConfiguration(array $tests)
101101
list($suite, $test) = explode(":", $test);
102102
$testConfiguration['suites'][$suite][] = $test;
103103
}
104-
return $testConfiguration;
104+
$testConfigurationJson = json_encode($testConfiguration);
105+
return $testConfigurationJson;
105106
}
106107
}

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7373
$verbose = $output->isVerbose();
7474
$allowSkipped = $input->getOption('allowSkipped');
7575

76-
// if test configuration is not specified, set implicitly
77-
if ($json === null && !empty($tests)) {
78-
$json = json_encode($this->getTestAndSuiteConfiguration($tests));
76+
if (!empty($tests)) {
77+
$json = $this->getTestAndSuiteConfiguration($tests);
7978
}
8079

8180
if ($json !== null && !json_decode($json)) {

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6363
);
6464
}
6565

66+
$testConfiguration = $this->getTestAndSuiteConfiguration($tests);
67+
6668
if (!$skipGeneration) {
67-
$testConfiguration = $this->getTestAndSuiteConfiguration($tests);
6869
$command = $this->getApplication()->find('generate:tests');
6970
$args = [
70-
'--tests' => json_encode($testConfiguration),
71+
'--tests' => $testConfiguration,
7172
'--force' => $force,
7273
'--remove' => $remove,
7374
'--debug' => $debug,
@@ -76,20 +77,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7677
$command->run(new ArrayInput($args), $output);
7778
}
7879
// tests with resolved suite references
79-
$resolvedTests = $this->getResolvedTests($testConfiguration);
80-
$returnCode = 0;
80+
$resolvedTests = $this->resolveSuiteReferences($testConfiguration);
81+
8182
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional ';
8283
$testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR;
84+
$returnCode = 0;
8385
//execute only tests specified as arguments in run command
8486
foreach ($resolvedTests as $test) {
8587
//set directory as suite name for tests in suite, if not set to "default"
8688
if (strpos($test, ':')) {
87-
list($suite, $testName) = explode(":", $test);
89+
list($testGroup, $testName) = explode(":", $test);
8890
} else {
89-
list($suite, $testName) = [TestGenerator::DEFAULT_DIR, $test];
91+
list($testGroup, $testName) = [TestGenerator::DEFAULT_DIR, $test];
9092
}
91-
$testGroup = $suite . DIRECTORY_SEPARATOR;
92-
$testName .= 'Cest.php';
93+
$testGroup = $testGroup . DIRECTORY_SEPARATOR;
94+
$testName = $testName . 'Cest.php';
9395
if (!realpath($testsDirectory . $testGroup . $testName)) {
9496
throw new TestFrameworkException(
9597
$testName . " is not available under " . $testsDirectory . $testGroup
@@ -111,12 +113,13 @@ function ($type, $buffer) use ($output) {
111113
}
112114

113115
/** Get an array of tests with resolved suite references from $testConfiguration
114-
* eg: if test is referenced in a suite, it'll be stored in format "SuiteName:Testname";
115-
* @param array $testConfiguration
116+
* eg: if test is referenced in a suite, it'll be stored in format suite:test
117+
* @param $testConfigurationJson
116118
* @return array
117119
*/
118-
private function getResolvedTests(array $testConfiguration)
120+
private function resolveSuiteReferences($testConfigurationJson)
119121
{
122+
$testConfiguration = json_decode($testConfigurationJson, true);
120123
$testsArray = $testConfiguration['tests'] ?? [];
121124
$suitesArray = $testConfiguration['suites'] ?? [];
122125
$testArrayBuilder = [];

0 commit comments

Comments
 (0)