Skip to content

Commit 09d8bfd

Browse files
committed
MQE-1782: MFTF run:group can't run test in a suite
- Removed old or unused code from implementation - Added unit tests
1 parent 8e7494d commit 09d8bfd

File tree

3 files changed

+58
-96
lines changed

3 files changed

+58
-96
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
1313
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
1414
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
15+
1516
class BaseGenerateCommandTest extends TestCase
1617
{
1718
public function tearDown()
1819
{
1920
AspectMock::clean();
2021
}
2122

22-
/**
23-
* One test in one suite
24-
*/
2523
public function testOneTestOneSuiteConfig()
2624
{
2725
$testOne = new TestObject('Test1', [], [], []);
@@ -37,10 +35,6 @@ public function testOneTestOneSuiteConfig()
3735
$this->assertEquals($expected, $actual);
3836
}
3937

40-
41-
/**
42-
* One test in one suite
43-
*/
4438
public function testOneTestTwoSuitesConfig()
4539
{
4640
$testOne = new TestObject('Test1', [], [], []);
@@ -87,6 +81,54 @@ public function testThreeTestsTwoGroup()
8781
$this->assertEquals($expected, $actual);
8882
}
8983

84+
public function testOneTestOneSuiteOneGroupConfig()
85+
{
86+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
87+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
88+
89+
$testArray = ['Test1' => $testOne];
90+
$suiteArray = ['Suite1' => $suiteOne];
91+
92+
$this->mockHandlers($testArray, $suiteArray);
93+
94+
$actual = json_decode($this->callGroupConfig(['Group1']), true);
95+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]];
96+
$this->assertEquals($expected, $actual);
97+
}
98+
99+
public function testTwoTestOneSuiteTwoGroupConfig()
100+
{
101+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
102+
$testTwo = new TestObject('Test2', [], ['group' => ['Group2']], []);
103+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne, 'Test2' => $testTwo], [], []);
104+
105+
$testArray = ['Test1' => $testOne, 'Test2' => $testTwo];
106+
$suiteArray = ['Suite1' => $suiteOne];
107+
108+
$this->mockHandlers($testArray, $suiteArray);
109+
110+
$actual = json_decode($this->callGroupConfig(['Group1', 'Group2']), true);
111+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1', 'Test2']]];
112+
$this->assertEquals($expected, $actual);
113+
}
114+
115+
public function testTwoTestTwoSuiteOneGroupConfig()
116+
{
117+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
118+
$testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []);
119+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
120+
$suiteTwo = new SuiteObject('Suite2', ['Test2' => $testTwo], [], []);
121+
122+
$testArray = ['Test1' => $testOne, 'Test2' => $testTwo];
123+
$suiteArray = ['Suite1' => $suiteOne, 'Suite2' => $suiteTwo];
124+
125+
$this->mockHandlers($testArray, $suiteArray);
126+
127+
$actual = json_decode($this->callGroupConfig(['Group1']), true);
128+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1'], 'Suite2' => ['Test2']]];
129+
$this->assertEquals($expected, $actual);
130+
}
131+
90132
/**
91133
* Mock handlers to skip parsing
92134
* @param array $testArray
@@ -95,7 +137,7 @@ public function testThreeTestsTwoGroup()
95137
*/
96138
public function mockHandlers($testArray, $suiteArray)
97139
{
98-
AspectMock::double(TestObjectHandler::class,['initTestData' => ''])->make();
140+
AspectMock::double(TestObjectHandler::class, ['initTestData' => ''])->make();
99141
$handler = TestObjectHandler::getInstance();
100142
$property = new \ReflectionProperty(TestObjectHandler::class, 'tests');
101143
$property->setAccessible(true);

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ protected function removeGeneratedDirectory(OutputInterface $output, bool $verbo
7676
* @return false|string
7777
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
7878
*/
79-
8079
protected function getTestAndSuiteConfiguration(array $tests)
8180
{
8281
$testConfiguration['tests'] = null;
@@ -105,7 +104,12 @@ protected function getTestAndSuiteConfiguration(array $tests)
105104
return $testConfigurationJson;
106105
}
107106

108-
/** second attempt at a cleaner implementation, needs work */
107+
/**
108+
* Returns an array of test configuration to be used as an argument for generation of tests
109+
* This function uses group or suite names for generation
110+
* @return false|string
111+
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
112+
*/
109113
protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames)
110114
{
111115
$result['tests'] = [];
@@ -143,15 +147,8 @@ protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames)
143147
);
144148

145149
foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) {
146-
$cat = $testsInSuites[$testInGroupAndInAnySuite][0];
147-
$dog[$cat][] = $testInGroupAndInAnySuite;
148-
149-
/*
150-
* todo -- I left off here. Code works so far.
151-
* I need to take this $dog array and put into the $result['suites'] array
152-
* and then test it thoroughly
153-
*/
154-
150+
$suiteName = $testsInSuites[$testInGroupAndInAnySuite][0];
151+
$result['suites'][$suiteName][] = $testInGroupAndInAnySuite;
155152
}
156153

157154
$result['tests'] = array_merge(

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -111,81 +111,4 @@ function ($type, $buffer) use ($output) {
111111
}
112112
);
113113
}
114-
115-
/**
116-
* Returns a json string to be used as an argument for generation of a group or suite
117-
*
118-
* @param array $groups
119-
* @return string
120-
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
121-
*/
122-
private function OLDgetGroupAndSuiteConfiguration(array $groups)
123-
{
124-
$testConfiguration['tests'] = [];
125-
$testConfiguration['suites'] = null;
126-
$availableSuites = SuiteObjectHandler::getInstance()->getAllObjects();
127-
128-
foreach ($groups as $group) {
129-
if (array_key_exists($group, $availableSuites)) {
130-
$testConfiguration['suites'][$group] = [];
131-
}
132-
133-
$testConfiguration['tests'] = array_merge(
134-
$testConfiguration['tests'],
135-
array_keys(TestObjectHandler::getInstance()->getTestsByGroup($group))
136-
);
137-
}
138-
139-
$testConfigurationJson = json_encode($testConfiguration);
140-
return $testConfigurationJson;
141-
}
142-
143-
/** first attempt at an implementation, needs tested */
144-
private function first_attempt_getGroupAndSuiteConfiguration(array $groups)
145-
{
146-
$testConfiguration['tests'] = [];
147-
$testConfiguration['suites'] = null;
148-
$availableSuites = SuiteObjectHandler::getInstance()->getAllObjects();
149-
150-
// iterate through all group names passed into the command
151-
foreach ($groups as $group) {
152-
if (array_key_exists($group, $availableSuites)) {
153-
// group is actually a suite, so add it to the suites array
154-
$testConfiguration['suites'][$group] = [];
155-
} else {
156-
// group is a group, so find and add all tests from that group to the tests array
157-
$testConfiguration['tests'] = array_merge(
158-
$testConfiguration['tests'],
159-
array_keys(TestObjectHandler::getInstance()->getTestsByGroup($group))
160-
);
161-
}
162-
}
163-
164-
// find all tests that are in suites and build pairs
165-
$testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences();
166-
$suiteToTestPair = [];
167-
foreach ($testConfiguration['tests'] as $test) {
168-
if (array_key_exists($test, $testsInSuites)) {
169-
$suites = $testsInSuites[$test];
170-
foreach ($suites as $suite) {
171-
$suiteToTestPair[] = "$suite:$test";
172-
}
173-
}
174-
}
175-
176-
// add tests to suites array
177-
$diff = [];
178-
foreach ($suiteToTestPair as $pair) {
179-
list($suite, $test) = explode(":", $pair);
180-
$testConfiguration['suites'][$suite][] = $test;
181-
$diff[] = $test;
182-
}
183-
184-
// remove tests in suites from the tests array
185-
$testConfiguration['tests'] = array_diff($testConfiguration['tests'], $diff);
186-
187-
// encode and return the result
188-
$testConfigurationJson = json_encode($testConfiguration);
189-
return $testConfigurationJson;
190-
}
191114
}

0 commit comments

Comments
 (0)