From b7ee3f89eeb665e88a0c818f669944ff0f679bf2 Mon Sep 17 00:00:00 2001 From: Tom Reece Date: Fri, 18 Oct 2019 13:28:38 -0500 Subject: [PATCH 1/6] Work in progress before vacation --- .../Console/RunTestGroupCommand.php | 110 +++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php index 7f954c8fe..86b349f53 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php @@ -119,7 +119,7 @@ function ($type, $buffer) use ($output) { * @return string * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException */ - private function getGroupAndSuiteConfiguration(array $groups) + private function OLDgetGroupAndSuiteConfiguration(array $groups) { $testConfiguration['tests'] = []; $testConfiguration['suites'] = null; @@ -139,4 +139,112 @@ private function getGroupAndSuiteConfiguration(array $groups) $testConfigurationJson = json_encode($testConfiguration); return $testConfigurationJson; } + + /** first attempt at an implementation, needs tested */ + private function first_attempt_getGroupAndSuiteConfiguration(array $groups) + { + $testConfiguration['tests'] = []; + $testConfiguration['suites'] = null; + $availableSuites = SuiteObjectHandler::getInstance()->getAllObjects(); + + // iterate through all group names passed into the command + foreach ($groups as $group) { + if (array_key_exists($group, $availableSuites)) { + // group is actually a suite, so add it to the suites array + $testConfiguration['suites'][$group] = []; + } else { + // group is a group, so find and add all tests from that group to the tests array + $testConfiguration['tests'] = array_merge( + $testConfiguration['tests'], + array_keys(TestObjectHandler::getInstance()->getTestsByGroup($group)) + ); + } + } + + // find all tests that are in suites and build pairs + $testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); + $suiteToTestPair = []; + foreach ($testConfiguration['tests'] as $test) { + if (array_key_exists($test, $testsInSuites)) { + $suites = $testsInSuites[$test]; + foreach ($suites as $suite) { + $suiteToTestPair[] = "$suite:$test"; + } + } + } + + // add tests to suites array + $diff = []; + foreach ($suiteToTestPair as $pair) { + list($suite, $test) = explode(":", $pair); + $testConfiguration['suites'][$suite][] = $test; + $diff[] = $test; + } + + // remove tests in suites from the tests array + $testConfiguration['tests'] = array_diff($testConfiguration['tests'], $diff); + + // encode and return the result + $testConfigurationJson = json_encode($testConfiguration); + return $testConfigurationJson; + } + + /** second attempt at a cleaner implementation, needs work */ + private function getGroupAndSuiteConfiguration(array $groupOrSuiteNames) + { + $result['tests'] = []; + $result['suites'] = null; + + $groups = []; + $suites = []; + + $allSuites = SuiteObjectHandler::getInstance()->getAllObjects(); + $testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); + + foreach ($groupOrSuiteNames as $groupOrSuiteName) { + if (array_key_exists($groupOrSuiteName, $allSuites)) { + $suites[] = $groupOrSuiteName; + } else { + $groups[] = $groupOrSuiteName; + } + } + + foreach ($suites as $suite) { + $result['suites'][$suite] = []; + } + + foreach ($groups as $group) { + $testsInGroup = TestObjectHandler::getInstance()->getTestsByGroup($group); + + $testsInGroupAndNotInAnySuite = array_diff( + array_keys($testsInGroup), + array_keys($testsInSuites) + ); + + $testsInGroupAndInAnySuite = array_diff( + array_keys($testsInGroup), + $testsInGroupAndNotInAnySuite + ); + + foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) { + $cat = $testsInSuites[$testInGroupAndInAnySuite][0]; + $dog[$cat][] = $testInGroupAndInAnySuite; + + /* + * todo -- I left off here. Code works so far. + * I need to take this $dog array and put into the $result['suites'] array + * and then test it thoroughly + */ + + } + + $result['tests'] = array_merge( + $result['tests'], + $testsInGroupAndNotInAnySuite + ); + } + + $json = json_encode($result); + return $json; + } } From d8c58af84dd91060947b7cf81e5088cd1340ef95 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Wed, 23 Oct 2019 14:29:55 -0500 Subject: [PATCH 2/6] MQE-1782: MFTF run:group can't run test in a suite - Added unit test template for test/suite configuration method --- .../Console/BaseGenerateCommandTest.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php new file mode 100644 index 000000000..d1933c7d8 --- /dev/null +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php @@ -0,0 +1,74 @@ + $testOne], [], []); + + $testArray = ['Test1' => $testOne]; + $suiteArray = ['Suite1' => $suiteOne]; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callConfig(['Test1']), true); + $expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]]; + $this->assertEquals($expected, $actual); + } + + /** + * Mock handlers to skip parsing + * @param array $testArray + * @param array $suiteArray + * @throws \Exception + */ + public function mockHandlers($testArray, $suiteArray) + { + AspectMock::double(TestObjectHandler::class,['initTestData' => ''])->make(); + $handler = TestObjectHandler::getInstance(); + $property = new \ReflectionProperty(TestObjectHandler::class, 'tests'); + $property->setAccessible(true); + $property->setValue($handler, $testArray); + + AspectMock::double(SuiteObjectHandler::class, ['initSuiteData' => ''])->make(); + $handler = SuiteObjectHandler::getInstance(); + $property = new \ReflectionProperty(SuiteObjectHandler::class, 'suiteObjects'); + $property->setAccessible(true); + $property->setValue($handler, $suiteArray); + } + + /** + * Changes visibility and runs getTestAndSuiteConfiguration + * @param array $testArray + * @return string + */ + public function callConfig($testArray) + { + $command = new BaseGenerateCommand(); + $class = new \ReflectionClass($command); + $method = $class->getMethod('getTestAndSuiteConfiguration'); + $method->setAccessible(true); + return $method->invokeArgs($command, [$testArray]); + } +} From 8e7494d91390ebf5a522205694a0f5262bd2fb89 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Thu, 24 Oct 2019 08:34:47 -0500 Subject: [PATCH 3/6] MQE-1782: MFTF run:group can't run test in a suite - Moved group config function to BaseGenerateCommand - Added more unit tests --- .../Console/BaseGenerateCommandTest.php | 70 ++++++++++++++++++- .../Console/BaseGenerateCommand.php | 67 ++++++++++++++++++ .../Console/RunTestGroupCommand.php | 59 ---------------- 3 files changed, 134 insertions(+), 62 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php index d1933c7d8..82a223726 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php @@ -22,7 +22,7 @@ public function tearDown() /** * One test in one suite */ - public function testSimpleTestConfig() + public function testOneTestOneSuiteConfig() { $testOne = new TestObject('Test1', [], [], []); $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []); @@ -32,11 +32,61 @@ public function testSimpleTestConfig() $this->mockHandlers($testArray, $suiteArray); - $actual = json_decode($this->callConfig(['Test1']), true); + $actual = json_decode($this->callTestConfig(['Test1']), true); $expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]]; $this->assertEquals($expected, $actual); } + + /** + * One test in one suite + */ + public function testOneTestTwoSuitesConfig() + { + $testOne = new TestObject('Test1', [], [], []); + $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []); + $suiteTwo = new SuiteObject('Suite2', ['Test1' => $testOne], [], []); + + $testArray = ['Test1' => $testOne]; + $suiteArray = ['Suite1' => $suiteOne, 'Suite2' => $suiteTwo]; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callTestConfig(['Test1']), true); + $expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1'], 'Suite2' => ['Test1']]]; + $this->assertEquals($expected, $actual); + } + + public function testOneTestOneGroup() + { + $testOne = new TestObject('Test1', [], ['group' => ['Group1']], []); + + $testArray = ['Test1' => $testOne]; + $suiteArray = []; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callGroupConfig(['Group1']), true); + $expected = ['tests' => ['Test1'], 'suites' => null]; + $this->assertEquals($expected, $actual); + } + + public function testThreeTestsTwoGroup() + { + $testOne = new TestObject('Test1', [], ['group' => ['Group1']], []); + $testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []); + $testThree = new TestObject('Test3', [], ['group' => ['Group2']], []); + + $testArray = ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree]; + $suiteArray = []; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callGroupConfig(['Group1', 'Group2']), true); + $expected = ['tests' => ['Test1', 'Test2', 'Test3'], 'suites' => null]; + $this->assertEquals($expected, $actual); + } + /** * Mock handlers to skip parsing * @param array $testArray @@ -63,7 +113,7 @@ public function mockHandlers($testArray, $suiteArray) * @param array $testArray * @return string */ - public function callConfig($testArray) + public function callTestConfig($testArray) { $command = new BaseGenerateCommand(); $class = new \ReflectionClass($command); @@ -71,4 +121,18 @@ public function callConfig($testArray) $method->setAccessible(true); return $method->invokeArgs($command, [$testArray]); } + + /** + * Changes visibility and runs getGroupAndSuiteConfiguration + * @param array $groupArray + * @return string + */ + public function callGroupConfig($groupArray) + { + $command = new BaseGenerateCommand(); + $class = new \ReflectionClass($command); + $method = $class->getMethod('getGroupAndSuiteConfiguration'); + $method->setAccessible(true); + return $method->invokeArgs($command, [$groupArray]); + } } diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index 87b203d66..0c7fff674 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -8,6 +8,7 @@ namespace Magento\FunctionalTestingFramework\Console; +use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -103,4 +104,70 @@ protected function getTestAndSuiteConfiguration(array $tests) $testConfigurationJson = json_encode($testConfiguration); return $testConfigurationJson; } + + /** second attempt at a cleaner implementation, needs work */ + protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames) + { + $result['tests'] = []; + $result['suites'] = []; + + $groups = []; + $suites = []; + + $allSuites = SuiteObjectHandler::getInstance()->getAllObjects(); + $testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); + + foreach ($groupOrSuiteNames as $groupOrSuiteName) { + if (array_key_exists($groupOrSuiteName, $allSuites)) { + $suites[] = $groupOrSuiteName; + } else { + $groups[] = $groupOrSuiteName; + } + } + + foreach ($suites as $suite) { + $result['suites'][$suite] = []; + } + + foreach ($groups as $group) { + $testsInGroup = TestObjectHandler::getInstance()->getTestsByGroup($group); + + $testsInGroupAndNotInAnySuite = array_diff( + array_keys($testsInGroup), + array_keys($testsInSuites) + ); + + $testsInGroupAndInAnySuite = array_diff( + array_keys($testsInGroup), + $testsInGroupAndNotInAnySuite + ); + + foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) { + $cat = $testsInSuites[$testInGroupAndInAnySuite][0]; + $dog[$cat][] = $testInGroupAndInAnySuite; + + /* + * todo -- I left off here. Code works so far. + * I need to take this $dog array and put into the $result['suites'] array + * and then test it thoroughly + */ + + } + + $result['tests'] = array_merge( + $result['tests'], + $testsInGroupAndNotInAnySuite + ); + } + + if (empty($result['tests'])) { + $result['tests'] = null; + } + if (empty($result['suites'])) { + $result['suites'] = null; + } + + $json = json_encode($result); + return $json; + } } diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php index 86b349f53..d31bf7873 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php @@ -188,63 +188,4 @@ private function first_attempt_getGroupAndSuiteConfiguration(array $groups) $testConfigurationJson = json_encode($testConfiguration); return $testConfigurationJson; } - - /** second attempt at a cleaner implementation, needs work */ - private function getGroupAndSuiteConfiguration(array $groupOrSuiteNames) - { - $result['tests'] = []; - $result['suites'] = null; - - $groups = []; - $suites = []; - - $allSuites = SuiteObjectHandler::getInstance()->getAllObjects(); - $testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); - - foreach ($groupOrSuiteNames as $groupOrSuiteName) { - if (array_key_exists($groupOrSuiteName, $allSuites)) { - $suites[] = $groupOrSuiteName; - } else { - $groups[] = $groupOrSuiteName; - } - } - - foreach ($suites as $suite) { - $result['suites'][$suite] = []; - } - - foreach ($groups as $group) { - $testsInGroup = TestObjectHandler::getInstance()->getTestsByGroup($group); - - $testsInGroupAndNotInAnySuite = array_diff( - array_keys($testsInGroup), - array_keys($testsInSuites) - ); - - $testsInGroupAndInAnySuite = array_diff( - array_keys($testsInGroup), - $testsInGroupAndNotInAnySuite - ); - - foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) { - $cat = $testsInSuites[$testInGroupAndInAnySuite][0]; - $dog[$cat][] = $testInGroupAndInAnySuite; - - /* - * todo -- I left off here. Code works so far. - * I need to take this $dog array and put into the $result['suites'] array - * and then test it thoroughly - */ - - } - - $result['tests'] = array_merge( - $result['tests'], - $testsInGroupAndNotInAnySuite - ); - } - - $json = json_encode($result); - return $json; - } } From 09d8bfd5bd10ad305c0dd7e4168e2f786c8c0b0a Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Fri, 25 Oct 2019 09:23:42 -0500 Subject: [PATCH 4/6] MQE-1782: MFTF run:group can't run test in a suite - Removed old or unused code from implementation - Added unit tests --- .../Console/BaseGenerateCommandTest.php | 58 ++++++++++++-- .../Console/BaseGenerateCommand.php | 19 ++--- .../Console/RunTestGroupCommand.php | 77 ------------------- 3 files changed, 58 insertions(+), 96 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php index 82a223726..2d4df8096 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php @@ -12,6 +12,7 @@ use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler; use Magento\FunctionalTestingFramework\Test\Objects\TestObject; use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler; + class BaseGenerateCommandTest extends TestCase { public function tearDown() @@ -19,9 +20,6 @@ public function tearDown() AspectMock::clean(); } - /** - * One test in one suite - */ public function testOneTestOneSuiteConfig() { $testOne = new TestObject('Test1', [], [], []); @@ -37,10 +35,6 @@ public function testOneTestOneSuiteConfig() $this->assertEquals($expected, $actual); } - - /** - * One test in one suite - */ public function testOneTestTwoSuitesConfig() { $testOne = new TestObject('Test1', [], [], []); @@ -87,6 +81,54 @@ public function testThreeTestsTwoGroup() $this->assertEquals($expected, $actual); } + public function testOneTestOneSuiteOneGroupConfig() + { + $testOne = new TestObject('Test1', [], ['group' => ['Group1']], []); + $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []); + + $testArray = ['Test1' => $testOne]; + $suiteArray = ['Suite1' => $suiteOne]; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callGroupConfig(['Group1']), true); + $expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]]; + $this->assertEquals($expected, $actual); + } + + public function testTwoTestOneSuiteTwoGroupConfig() + { + $testOne = new TestObject('Test1', [], ['group' => ['Group1']], []); + $testTwo = new TestObject('Test2', [], ['group' => ['Group2']], []); + $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne, 'Test2' => $testTwo], [], []); + + $testArray = ['Test1' => $testOne, 'Test2' => $testTwo]; + $suiteArray = ['Suite1' => $suiteOne]; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callGroupConfig(['Group1', 'Group2']), true); + $expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1', 'Test2']]]; + $this->assertEquals($expected, $actual); + } + + public function testTwoTestTwoSuiteOneGroupConfig() + { + $testOne = new TestObject('Test1', [], ['group' => ['Group1']], []); + $testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []); + $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []); + $suiteTwo = new SuiteObject('Suite2', ['Test2' => $testTwo], [], []); + + $testArray = ['Test1' => $testOne, 'Test2' => $testTwo]; + $suiteArray = ['Suite1' => $suiteOne, 'Suite2' => $suiteTwo]; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callGroupConfig(['Group1']), true); + $expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1'], 'Suite2' => ['Test2']]]; + $this->assertEquals($expected, $actual); + } + /** * Mock handlers to skip parsing * @param array $testArray @@ -95,7 +137,7 @@ public function testThreeTestsTwoGroup() */ public function mockHandlers($testArray, $suiteArray) { - AspectMock::double(TestObjectHandler::class,['initTestData' => ''])->make(); + AspectMock::double(TestObjectHandler::class, ['initTestData' => ''])->make(); $handler = TestObjectHandler::getInstance(); $property = new \ReflectionProperty(TestObjectHandler::class, 'tests'); $property->setAccessible(true); diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index 0c7fff674..d99839d7c 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -76,7 +76,6 @@ protected function removeGeneratedDirectory(OutputInterface $output, bool $verbo * @return false|string * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException */ - protected function getTestAndSuiteConfiguration(array $tests) { $testConfiguration['tests'] = null; @@ -105,7 +104,12 @@ protected function getTestAndSuiteConfiguration(array $tests) return $testConfigurationJson; } - /** second attempt at a cleaner implementation, needs work */ + /** + * Returns an array of test configuration to be used as an argument for generation of tests + * This function uses group or suite names for generation + * @return false|string + * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException + */ protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames) { $result['tests'] = []; @@ -143,15 +147,8 @@ protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames) ); foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) { - $cat = $testsInSuites[$testInGroupAndInAnySuite][0]; - $dog[$cat][] = $testInGroupAndInAnySuite; - - /* - * todo -- I left off here. Code works so far. - * I need to take this $dog array and put into the $result['suites'] array - * and then test it thoroughly - */ - + $suiteName = $testsInSuites[$testInGroupAndInAnySuite][0]; + $result['suites'][$suiteName][] = $testInGroupAndInAnySuite; } $result['tests'] = array_merge( diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php index d31bf7873..98d121d40 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php @@ -111,81 +111,4 @@ function ($type, $buffer) use ($output) { } ); } - - /** - * Returns a json string to be used as an argument for generation of a group or suite - * - * @param array $groups - * @return string - * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException - */ - private function OLDgetGroupAndSuiteConfiguration(array $groups) - { - $testConfiguration['tests'] = []; - $testConfiguration['suites'] = null; - $availableSuites = SuiteObjectHandler::getInstance()->getAllObjects(); - - foreach ($groups as $group) { - if (array_key_exists($group, $availableSuites)) { - $testConfiguration['suites'][$group] = []; - } - - $testConfiguration['tests'] = array_merge( - $testConfiguration['tests'], - array_keys(TestObjectHandler::getInstance()->getTestsByGroup($group)) - ); - } - - $testConfigurationJson = json_encode($testConfiguration); - return $testConfigurationJson; - } - - /** first attempt at an implementation, needs tested */ - private function first_attempt_getGroupAndSuiteConfiguration(array $groups) - { - $testConfiguration['tests'] = []; - $testConfiguration['suites'] = null; - $availableSuites = SuiteObjectHandler::getInstance()->getAllObjects(); - - // iterate through all group names passed into the command - foreach ($groups as $group) { - if (array_key_exists($group, $availableSuites)) { - // group is actually a suite, so add it to the suites array - $testConfiguration['suites'][$group] = []; - } else { - // group is a group, so find and add all tests from that group to the tests array - $testConfiguration['tests'] = array_merge( - $testConfiguration['tests'], - array_keys(TestObjectHandler::getInstance()->getTestsByGroup($group)) - ); - } - } - - // find all tests that are in suites and build pairs - $testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences(); - $suiteToTestPair = []; - foreach ($testConfiguration['tests'] as $test) { - if (array_key_exists($test, $testsInSuites)) { - $suites = $testsInSuites[$test]; - foreach ($suites as $suite) { - $suiteToTestPair[] = "$suite:$test"; - } - } - } - - // add tests to suites array - $diff = []; - foreach ($suiteToTestPair as $pair) { - list($suite, $test) = explode(":", $pair); - $testConfiguration['suites'][$suite][] = $test; - $diff[] = $test; - } - - // remove tests in suites from the tests array - $testConfiguration['tests'] = array_diff($testConfiguration['tests'], $diff); - - // encode and return the result - $testConfigurationJson = json_encode($testConfiguration); - return $testConfigurationJson; - } } From 2a9df738db3cec1bce7fd18624b7b4312ccf1bfa Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Mon, 28 Oct 2019 13:44:54 -0500 Subject: [PATCH 5/6] MQE-1782: MFTF run:group can't run test in a suite - Fixed mixed group/suite usecase - Added Unit test --- .../Console/BaseGenerateCommandTest.php | 22 +++++++++++++++++++ .../Console/BaseGenerateCommand.php | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php index 2d4df8096..f46becaa5 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php @@ -129,6 +129,28 @@ public function testTwoTestTwoSuiteOneGroupConfig() $this->assertEquals($expected, $actual); } + /** + * Test specific usecase of a test that is in a group with the group being called along with the suite + * i.e. run:group Group1 Suite1 + * @throws \Exception + */ + public function testThreeTestOneSuiteOneGroupMix() + { + $testOne = new TestObject('Test1', [], [], []); + $testTwo = new TestObject('Test2', [], [], []); + $testThree = new TestObject('Test3', [], ['group' => ['Group1']], []); + $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree], [], []); + + $testArray = ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree]; + $suiteArray = ['Suite1' => $suiteOne]; + + $this->mockHandlers($testArray, $suiteArray); + + $actual = json_decode($this->callGroupConfig(['Group1', 'Suite1']), true); + $expected = ['tests' => null, 'suites' => ['Suite1' => []]]; + $this->assertEquals($expected, $actual); + } + /** * Mock handlers to skip parsing * @param array $testArray diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index d99839d7c..244610877 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -148,6 +148,10 @@ protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames) foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) { $suiteName = $testsInSuites[$testInGroupAndInAnySuite][0]; + if (isset($result['suites'][$suiteName])) { + // Suite is already being called to run in its entirety, do not filter list + continue; + } $result['suites'][$suiteName][] = $testInGroupAndInAnySuite; } From 9cb452badb4c4353b80eb877bd0320903a5ea0e1 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Mon, 28 Oct 2019 14:23:50 -0500 Subject: [PATCH 6/6] MQE-1782: MFTF run:group can't run test in a suite - changed from isset to array_search - fixed static check --- .../Console/BaseGenerateCommandTest.php | 7 ++++++- .../Console/BaseGenerateCommand.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php index f46becaa5..1b1686ce2 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php @@ -139,7 +139,12 @@ public function testThreeTestOneSuiteOneGroupMix() $testOne = new TestObject('Test1', [], [], []); $testTwo = new TestObject('Test2', [], [], []); $testThree = new TestObject('Test3', [], ['group' => ['Group1']], []); - $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree], [], []); + $suiteOne = new SuiteObject( + 'Suite1', + ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree], + [], + [] + ); $testArray = ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree]; $suiteArray = ['Suite1' => $suiteOne]; diff --git a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php index 244610877..5afaf17c5 100644 --- a/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php @@ -148,7 +148,7 @@ protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames) foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) { $suiteName = $testsInSuites[$testInGroupAndInAnySuite][0]; - if (isset($result['suites'][$suiteName])) { + if (array_search($suiteName, $suites) !== false) { // Suite is already being called to run in its entirety, do not filter list continue; }