From 315616f97db14186e8f4f805e615cd5ac6342347 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 28 Aug 2019 08:55:12 -0500 Subject: [PATCH 01/10] MQE-1703: Implicit Suite Generation for Tests --- .../Console/BaseGenerateCommand.php | 32 ++++++++++++++ .../Console/GenerateTestsCommand.php | 11 +++-- .../Console/RunTestCommand.php | 44 +++++++++++++++---- 3 files changed, 75 insertions(+), 12 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index 75c521379..afe2f6916 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -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,35 @@ protected function removeGeneratedDirectory(OutputInterface $output, bool $verbo } } } + + /** + * Returns a 2D array of tests with their suites references that can be encoded into a json test configuration + * @param array $tests + * @return false|string + * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException + */ + + protected function getTestAndSuiteConfiguration(array $tests) + { + $testConfiguration['tests'] = []; + $testConfiguration['suites'] = []; + $allSuiteTests = SuiteObjectHandler::getInstance()->getAllTestReferences(); + $suiteGroup = []; + + foreach($tests as $test) { + if (array_key_exists($test, $allSuiteTests)) { + $suiteGroup[$test] = $allSuiteTests[$test]; + } + else $testConfiguration['tests'][] = $test; + } + + foreach ($suiteGroup as $test => $suites) { + + foreach ($suites as $suite) { + $testConfiguration['suites'][$suite][] = $test; + } + + } + return $testConfiguration; + } } diff --git a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php index ca9d6e3cc..0a92e5dab 100644 --- a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $tests = $input->getArgument('name'); $config = $input->getOption('config'); - $json = $input->getOption('tests'); + $json = $input->getOption('tests'); // for backward compatibility $force = $input->getOption('force'); $time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds $debug = $input->getOption('debug') ?? MftfApplicationConfig::LEVEL_DEVELOPER; // for backward compatibility @@ -73,6 +73,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $verbose = $output->isVerbose(); $allowSkipped = $input->getOption('allowSkipped'); + // if test configuration is not specified, set implicitly + if ($json === null && !empty($tests)) { + $json = json_encode($this->getTestAndSuiteConfiguration($tests)); + } + if ($json !== null && !json_decode($json)) { // stop execution if we have failed to properly parse any json passed in by the user throw new TestFrameworkException("JSON could not be parsed: " . json_last_error_msg()); @@ -100,9 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $testManifest->createTestGroups($time); } - if (empty($tests)) { - SuiteGenerator::getInstance()->generateAllSuites($testManifest); - } + SuiteGenerator::getInstance()->generateAllSuites($testManifest); $testManifest->generate(); diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index b17131459..b0c47c7eb 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -64,12 +64,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if (!$skipGeneration) { + $testConfiguration = $this->getTestAndSuiteConfiguration($tests); $command = $this->getApplication()->find('generate:tests'); $args = [ - '--tests' => json_encode([ - 'tests' => $tests, - 'suites' => null - ]), + '--tests' => json_encode($testConfiguration), '--force' => $force, '--remove' => $remove, '--debug' => $debug, @@ -77,14 +75,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int ]; $command->run(new ArrayInput($args), $output); } - + // tests with resolved suite references + $resolvedTests = $this->getResolvedTests($testConfiguration); $returnCode = 0; $codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional '; $testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR; //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){ + // for tests in suite, set directory as suite name + if (strpos($test, ':' )) { + list($suite, $testName) = explode(":", $test); + } + // for standalone tests set directory as "default" + else { + list($suite, $testName) = [TestGenerator::DEFAULT_DIR, $test]; + } + $testGroup = $suite . DIRECTORY_SEPARATOR; + $testName .= 'Cest.php'; if (!realpath($testsDirectory . $testGroup . $testName)) { throw new TestFrameworkException( $testName . " is not available under " . $testsDirectory . $testGroup @@ -104,4 +111,25 @@ function ($type, $buffer) use ($output) { } return $returnCode; } + + /** Get an array of tests with resolved suite references from $testConfiguration + * eg: if test is referenced in a suite, it'll be stored in format "SuiteName:Testname"; + * if not it'll be stored as is. + * @param $testConfiguration + * @return array + */ + private function getResolvedTests($testConfiguration) + { + $testsArray = $testConfiguration['tests'] ?? []; + $suitesArray = $testConfiguration['suites'] ?? []; + $testArrayBuilder = []; + foreach ($suitesArray as $suite => $tests) { + $testArrayBuilder = array_merge($testArrayBuilder, + array_map(function($test) use ($suite) + { return $suite . ':' . $test ; }, $tests)); + } + return array_merge($testArrayBuilder, $testsArray); + + + } } From 5ba993ad1e81c1af743e346d5bc5f2833b8bc26f Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 28 Aug 2019 10:10:42 -0500 Subject: [PATCH 02/10] MQE-1703: Implicit Suite Generation for Tests fixing unit tests --- .../Console/BaseGenerateCommand.php | 2 -- .../Console/RunTestCommand.php | 21 ++++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index afe2f6916..a14b83c0f 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -91,11 +91,9 @@ protected function getTestAndSuiteConfiguration(array $tests) } foreach ($suiteGroup as $test => $suites) { - foreach ($suites as $suite) { $testConfiguration['suites'][$suite][] = $test; } - } return $testConfiguration; } diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index b0c47c7eb..ecbf9ec7b 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -81,9 +81,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional '; $testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR; //execute only tests specified as arguments in run command - foreach ($resolvedTests as $test){ + foreach ($resolvedTests as $test) { // for tests in suite, set directory as suite name - if (strpos($test, ':' )) { + if (strpos($test, ':')) { list($suite, $testName) = explode(":", $test); } // for standalone tests set directory as "default" @@ -114,22 +114,23 @@ function ($type, $buffer) use ($output) { /** Get an array of tests with resolved suite references from $testConfiguration * eg: if test is referenced in a suite, it'll be stored in format "SuiteName:Testname"; - * if not it'll be stored as is. - * @param $testConfiguration + * @param array $testConfiguration * @return array */ - private function getResolvedTests($testConfiguration) + private function getResolvedTests(array $testConfiguration) { $testsArray = $testConfiguration['tests'] ?? []; $suitesArray = $testConfiguration['suites'] ?? []; $testArrayBuilder = []; + foreach ($suitesArray as $suite => $tests) { - $testArrayBuilder = array_merge($testArrayBuilder, - array_map(function($test) use ($suite) - { return $suite . ':' . $test ; }, $tests)); + $testArrayBuilder = array_merge( + $testArrayBuilder, + array_map(function ($test) use ($suite) { + return $suite . ':' . $test; + }, $tests) + ); } return array_merge($testArrayBuilder, $testsArray); - - } } From 32827704c8f1e93710232c6a7a588d0dcb3afbf4 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 28 Aug 2019 10:25:49 -0500 Subject: [PATCH 03/10] MQE-1703: Implicit Suite Generation for Tests fixing unit tests --- .../FunctionalTestingFramework/Console/RunTestCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index ecbf9ec7b..d58d95fdc 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -82,11 +82,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR; //execute only tests specified as arguments in run command foreach ($resolvedTests as $test) { - // for tests in suite, set directory as suite name + //set directory as suite name for tests in suite, if not set to "default" if (strpos($test, ':')) { list($suite, $testName) = explode(":", $test); } - // for standalone tests set directory as "default" else { list($suite, $testName) = [TestGenerator::DEFAULT_DIR, $test]; } From 79ff34748397aeb46377f0a0ae75c11c307f241a Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 28 Aug 2019 10:59:33 -0500 Subject: [PATCH 04/10] MQE-1703: Implicit Suite Generation for Tests fixing unit tests --- .../FunctionalTestingFramework/Console/BaseGenerateCommand.php | 2 +- .../FunctionalTestingFramework/Console/RunTestCommand.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index a14b83c0f..46f3db95e 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -70,7 +70,7 @@ protected function removeGeneratedDirectory(OutputInterface $output, bool $verbo } /** - * Returns a 2D array of tests with their suites references that can be encoded into a json test configuration + * 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 diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index d58d95fdc..09f36ae41 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -85,8 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int //set directory as suite name for tests in suite, if not set to "default" if (strpos($test, ':')) { list($suite, $testName) = explode(":", $test); - } - else { + } else { list($suite, $testName) = [TestGenerator::DEFAULT_DIR, $test]; } $testGroup = $suite . DIRECTORY_SEPARATOR; From 1a2dc67dacb23590f7debe3218b78b48b5f52236 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 28 Aug 2019 16:39:23 -0500 Subject: [PATCH 05/10] MQE-1703: Implicit Suite Generation for Tests fixing unit tests --- .../Console/BaseGenerateCommand.php | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index 46f3db95e..d8c7a53ce 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -80,20 +80,26 @@ protected function getTestAndSuiteConfiguration(array $tests) { $testConfiguration['tests'] = []; $testConfiguration['suites'] = []; - $allSuiteTests = SuiteObjectHandler::getInstance()->getAllTestReferences(); - $suiteGroup = []; + $testsReferencedInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); + $resolvedTests = []; foreach($tests as $test) { - if (array_key_exists($test, $allSuiteTests)) { - $suiteGroup[$test] = $allSuiteTests[$test]; + if (array_key_exists($test, $testsReferencedInSuites)) { + $suites = $testsReferencedInSuites[$test]; + $resolvedTests = array_merge( + $resolvedTests, + array_map(function ($value) use ($test) { + return $value . ':' . $test; + }, $suites) + ); } + // configuration for tests else $testConfiguration['tests'][] = $test; } - - foreach ($suiteGroup as $test => $suites) { - foreach ($suites as $suite) { - $testConfiguration['suites'][$suite][] = $test; - } + // configuration for suites + foreach ($resolvedTests as $test) { + list($suite, $test) = explode(":", $test); + $testConfiguration['suites'][$suite][] = $test; } return $testConfiguration; } From 4bbfb25f1b47c6f755edd11e23f607cc8e111130 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 28 Aug 2019 20:35:32 -0500 Subject: [PATCH 06/10] MQE-1703: Implicit Suite Generation for Tests fixing unit tests --- .../Console/BaseGenerateCommand.php | 3 ++- .../Console/GenerateTestsCommand.php | 5 ++-- .../Console/RunTestCommand.php | 25 +++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index d8c7a53ce..1cfa34e5a 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -101,6 +101,7 @@ protected function getTestAndSuiteConfiguration(array $tests) list($suite, $test) = explode(":", $test); $testConfiguration['suites'][$suite][] = $test; } - return $testConfiguration; + $testConfigurationJson = json_encode($testConfiguration); + return $testConfigurationJson; } } diff --git a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php index 0a92e5dab..c410973c7 100644 --- a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php @@ -73,9 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $verbose = $output->isVerbose(); $allowSkipped = $input->getOption('allowSkipped'); - // if test configuration is not specified, set implicitly - if ($json === null && !empty($tests)) { - $json = json_encode($this->getTestAndSuiteConfiguration($tests)); + if (!empty($tests)) { + $json = $this->getTestAndSuiteConfiguration($tests); } if ($json !== null && !json_decode($json)) { diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index 09f36ae41..6dbd8fc5b 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -63,11 +63,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + $testConfiguration = $this->getTestAndSuiteConfiguration($tests); + if (!$skipGeneration) { - $testConfiguration = $this->getTestAndSuiteConfiguration($tests); $command = $this->getApplication()->find('generate:tests'); $args = [ - '--tests' => json_encode($testConfiguration), + '--tests' => $testConfiguration, '--force' => $force, '--remove' => $remove, '--debug' => $debug, @@ -76,20 +77,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int $command->run(new ArrayInput($args), $output); } // tests with resolved suite references - $resolvedTests = $this->getResolvedTests($testConfiguration); - $returnCode = 0; + $resolvedTests = $this->resolveSuiteReferences($testConfiguration); + $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 ($resolvedTests as $test) { //set directory as suite name for tests in suite, if not set to "default" if (strpos($test, ':')) { - list($suite, $testName) = explode(":", $test); + list($testGroup, $testName) = explode(":", $test); } else { - list($suite, $testName) = [TestGenerator::DEFAULT_DIR, $test]; + list($testGroup, $testName) = [TestGenerator::DEFAULT_DIR, $test]; } - $testGroup = $suite . DIRECTORY_SEPARATOR; - $testName .= 'Cest.php'; + $testGroup = $testGroup . DIRECTORY_SEPARATOR; + $testName = $testName . 'Cest.php'; if (!realpath($testsDirectory . $testGroup . $testName)) { throw new TestFrameworkException( $testName . " is not available under " . $testsDirectory . $testGroup @@ -111,12 +113,13 @@ function ($type, $buffer) use ($output) { } /** Get an array of tests with resolved suite references from $testConfiguration - * eg: if test is referenced in a suite, it'll be stored in format "SuiteName:Testname"; - * @param array $testConfiguration + * eg: if test is referenced in a suite, it'll be stored in format suite:test + * @param $testConfigurationJson * @return array */ - private function getResolvedTests(array $testConfiguration) + private function resolveSuiteReferences($testConfigurationJson) { + $testConfiguration = json_decode($testConfigurationJson, true); $testsArray = $testConfiguration['tests'] ?? []; $suitesArray = $testConfiguration['suites'] ?? []; $testArrayBuilder = []; From da509f2bf4e295d400a9ec8ea1db6d6bfad5215e Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 28 Aug 2019 20:56:12 -0500 Subject: [PATCH 07/10] MQE-1703: Implicit Suite Generation for Tests fixing unit tests --- .../FunctionalTestingFramework/Console/RunTestCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index 6dbd8fc5b..0a355e798 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -114,7 +114,7 @@ function ($type, $buffer) use ($output) { /** Get an array of tests with resolved suite references from $testConfiguration * eg: if test is referenced in a suite, it'll be stored in format suite:test - * @param $testConfigurationJson + * @param string $testConfigurationJson * @return array */ private function resolveSuiteReferences($testConfigurationJson) From f353afe16cf002135973208ed52f682c5dfd59f2 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 4 Sep 2019 13:53:57 -0500 Subject: [PATCH 08/10] MQE-1703: Implicit Suite Generation for Tests fixing bug with test generation --- .../Console/BaseGenerateCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index 1cfa34e5a..61bd4cb66 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -78,8 +78,8 @@ protected function removeGeneratedDirectory(OutputInterface $output, bool $verbo protected function getTestAndSuiteConfiguration(array $tests) { - $testConfiguration['tests'] = []; - $testConfiguration['suites'] = []; + $testConfiguration['tests'] = null; + $testConfiguration['suites'] = null; $testsReferencedInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); $resolvedTests = []; From 4a519fe0bbedfadf4bddfc3434ce371e2da04744 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Thu, 5 Sep 2019 10:21:59 -0500 Subject: [PATCH 09/10] MQE-1703: Implicit Suite Generation for Tests Style fixes --- .../Console/BaseGenerateCommand.php | 19 +++++++++---------- .../Console/RunTestCommand.php | 12 +++++------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index 61bd4cb66..40582db86 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -81,24 +81,23 @@ protected function getTestAndSuiteConfiguration(array $tests) $testConfiguration['tests'] = null; $testConfiguration['suites'] = null; $testsReferencedInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); - $resolvedTests = []; + $suiteToTestPair = []; foreach($tests as $test) { if (array_key_exists($test, $testsReferencedInSuites)) { $suites = $testsReferencedInSuites[$test]; - $resolvedTests = array_merge( - $resolvedTests, - array_map(function ($value) use ($test) { - return $value . ':' . $test; - }, $suites) - ); + foreach ($suites as $suite) { + $suiteToTestPair[] = "$suite:$test"; + } } // configuration for tests - else $testConfiguration['tests'][] = $test; + else { + $testConfiguration['tests'][] = $test; + } } // configuration for suites - foreach ($resolvedTests as $test) { - list($suite, $test) = explode(":", $test); + foreach ($suiteToTestPair as $pair) { + list($suite, $test) = explode(":", $pair); $testConfiguration['suites'][$suite][] = $test; } $testConfigurationJson = json_encode($testConfiguration); diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index 0a355e798..cc23300c4 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -112,7 +112,8 @@ function ($type, $buffer) use ($output) { return $returnCode; } - /** Get an array of tests with resolved suite references from $testConfiguration + /** + * Get an array of tests with resolved suite references from $testConfiguration * eg: if test is referenced in a suite, it'll be stored in format suite:test * @param string $testConfigurationJson * @return array @@ -125,12 +126,9 @@ private function resolveSuiteReferences($testConfigurationJson) $testArrayBuilder = []; foreach ($suitesArray as $suite => $tests) { - $testArrayBuilder = array_merge( - $testArrayBuilder, - array_map(function ($test) use ($suite) { - return $suite . ':' . $test; - }, $tests) - ); + foreach($tests as $test){ + $testArrayBuilder[] = "$suite:$test"; + } } return array_merge($testArrayBuilder, $testsArray); } From 5f81deb45497c4c9f2bb3f7f93856e47bf078f42 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Thu, 5 Sep 2019 10:32:24 -0500 Subject: [PATCH 10/10] MQE-1703: Implicit Suite Generation for Tests style fixes --- .../FunctionalTestingFramework/Console/RunTestCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index cc23300c4..e1e30589d 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -126,7 +126,7 @@ private function resolveSuiteReferences($testConfigurationJson) $testArrayBuilder = []; foreach ($suitesArray as $suite => $tests) { - foreach($tests as $test){ + foreach ($tests as $test) { $testArrayBuilder[] = "$suite:$test"; } }