Skip to content

Commit 8e7494d

Browse files
committed
MQE-1782: MFTF run:group can't run test in a suite
- Moved group config function to BaseGenerateCommand - Added more unit tests
1 parent d8c58af commit 8e7494d

File tree

3 files changed

+134
-62
lines changed

3 files changed

+134
-62
lines changed

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

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function tearDown()
2222
/**
2323
* One test in one suite
2424
*/
25-
public function testSimpleTestConfig()
25+
public function testOneTestOneSuiteConfig()
2626
{
2727
$testOne = new TestObject('Test1', [], [], []);
2828
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
@@ -32,11 +32,61 @@ public function testSimpleTestConfig()
3232

3333
$this->mockHandlers($testArray, $suiteArray);
3434

35-
$actual = json_decode($this->callConfig(['Test1']), true);
35+
$actual = json_decode($this->callTestConfig(['Test1']), true);
3636
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]];
3737
$this->assertEquals($expected, $actual);
3838
}
3939

40+
41+
/**
42+
* One test in one suite
43+
*/
44+
public function testOneTestTwoSuitesConfig()
45+
{
46+
$testOne = new TestObject('Test1', [], [], []);
47+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
48+
$suiteTwo = new SuiteObject('Suite2', ['Test1' => $testOne], [], []);
49+
50+
$testArray = ['Test1' => $testOne];
51+
$suiteArray = ['Suite1' => $suiteOne, 'Suite2' => $suiteTwo];
52+
53+
$this->mockHandlers($testArray, $suiteArray);
54+
55+
$actual = json_decode($this->callTestConfig(['Test1']), true);
56+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1'], 'Suite2' => ['Test1']]];
57+
$this->assertEquals($expected, $actual);
58+
}
59+
60+
public function testOneTestOneGroup()
61+
{
62+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
63+
64+
$testArray = ['Test1' => $testOne];
65+
$suiteArray = [];
66+
67+
$this->mockHandlers($testArray, $suiteArray);
68+
69+
$actual = json_decode($this->callGroupConfig(['Group1']), true);
70+
$expected = ['tests' => ['Test1'], 'suites' => null];
71+
$this->assertEquals($expected, $actual);
72+
}
73+
74+
public function testThreeTestsTwoGroup()
75+
{
76+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
77+
$testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []);
78+
$testThree = new TestObject('Test3', [], ['group' => ['Group2']], []);
79+
80+
$testArray = ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree];
81+
$suiteArray = [];
82+
83+
$this->mockHandlers($testArray, $suiteArray);
84+
85+
$actual = json_decode($this->callGroupConfig(['Group1', 'Group2']), true);
86+
$expected = ['tests' => ['Test1', 'Test2', 'Test3'], 'suites' => null];
87+
$this->assertEquals($expected, $actual);
88+
}
89+
4090
/**
4191
* Mock handlers to skip parsing
4292
* @param array $testArray
@@ -63,12 +113,26 @@ public function mockHandlers($testArray, $suiteArray)
63113
* @param array $testArray
64114
* @return string
65115
*/
66-
public function callConfig($testArray)
116+
public function callTestConfig($testArray)
67117
{
68118
$command = new BaseGenerateCommand();
69119
$class = new \ReflectionClass($command);
70120
$method = $class->getMethod('getTestAndSuiteConfiguration');
71121
$method->setAccessible(true);
72122
return $method->invokeArgs($command, [$testArray]);
73123
}
124+
125+
/**
126+
* Changes visibility and runs getGroupAndSuiteConfiguration
127+
* @param array $groupArray
128+
* @return string
129+
*/
130+
public function callGroupConfig($groupArray)
131+
{
132+
$command = new BaseGenerateCommand();
133+
$class = new \ReflectionClass($command);
134+
$method = $class->getMethod('getGroupAndSuiteConfiguration');
135+
$method->setAccessible(true);
136+
return $method->invokeArgs($command, [$groupArray]);
137+
}
74138
}

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\FunctionalTestingFramework\Console;
1010

11+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Input\InputOption;
1314
use Symfony\Component\Console\Output\OutputInterface;
@@ -103,4 +104,70 @@ protected function getTestAndSuiteConfiguration(array $tests)
103104
$testConfigurationJson = json_encode($testConfiguration);
104105
return $testConfigurationJson;
105106
}
107+
108+
/** second attempt at a cleaner implementation, needs work */
109+
protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames)
110+
{
111+
$result['tests'] = [];
112+
$result['suites'] = [];
113+
114+
$groups = [];
115+
$suites = [];
116+
117+
$allSuites = SuiteObjectHandler::getInstance()->getAllObjects();
118+
$testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences();
119+
120+
foreach ($groupOrSuiteNames as $groupOrSuiteName) {
121+
if (array_key_exists($groupOrSuiteName, $allSuites)) {
122+
$suites[] = $groupOrSuiteName;
123+
} else {
124+
$groups[] = $groupOrSuiteName;
125+
}
126+
}
127+
128+
foreach ($suites as $suite) {
129+
$result['suites'][$suite] = [];
130+
}
131+
132+
foreach ($groups as $group) {
133+
$testsInGroup = TestObjectHandler::getInstance()->getTestsByGroup($group);
134+
135+
$testsInGroupAndNotInAnySuite = array_diff(
136+
array_keys($testsInGroup),
137+
array_keys($testsInSuites)
138+
);
139+
140+
$testsInGroupAndInAnySuite = array_diff(
141+
array_keys($testsInGroup),
142+
$testsInGroupAndNotInAnySuite
143+
);
144+
145+
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+
155+
}
156+
157+
$result['tests'] = array_merge(
158+
$result['tests'],
159+
$testsInGroupAndNotInAnySuite
160+
);
161+
}
162+
163+
if (empty($result['tests'])) {
164+
$result['tests'] = null;
165+
}
166+
if (empty($result['suites'])) {
167+
$result['suites'] = null;
168+
}
169+
170+
$json = json_encode($result);
171+
return $json;
172+
}
106173
}

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -188,63 +188,4 @@ private function first_attempt_getGroupAndSuiteConfiguration(array $groups)
188188
$testConfigurationJson = json_encode($testConfiguration);
189189
return $testConfigurationJson;
190190
}
191-
192-
/** second attempt at a cleaner implementation, needs work */
193-
private function getGroupAndSuiteConfiguration(array $groupOrSuiteNames)
194-
{
195-
$result['tests'] = [];
196-
$result['suites'] = null;
197-
198-
$groups = [];
199-
$suites = [];
200-
201-
$allSuites = SuiteObjectHandler::getInstance()->getAllObjects();
202-
$testsInSuites = SuiteObjectHandler::getInstance()->getAllTestReferences();
203-
204-
foreach ($groupOrSuiteNames as $groupOrSuiteName) {
205-
if (array_key_exists($groupOrSuiteName, $allSuites)) {
206-
$suites[] = $groupOrSuiteName;
207-
} else {
208-
$groups[] = $groupOrSuiteName;
209-
}
210-
}
211-
212-
foreach ($suites as $suite) {
213-
$result['suites'][$suite] = [];
214-
}
215-
216-
foreach ($groups as $group) {
217-
$testsInGroup = TestObjectHandler::getInstance()->getTestsByGroup($group);
218-
219-
$testsInGroupAndNotInAnySuite = array_diff(
220-
array_keys($testsInGroup),
221-
array_keys($testsInSuites)
222-
);
223-
224-
$testsInGroupAndInAnySuite = array_diff(
225-
array_keys($testsInGroup),
226-
$testsInGroupAndNotInAnySuite
227-
);
228-
229-
foreach ($testsInGroupAndInAnySuite as $testInGroupAndInAnySuite) {
230-
$cat = $testsInSuites[$testInGroupAndInAnySuite][0];
231-
$dog[$cat][] = $testInGroupAndInAnySuite;
232-
233-
/*
234-
* todo -- I left off here. Code works so far.
235-
* I need to take this $dog array and put into the $result['suites'] array
236-
* and then test it thoroughly
237-
*/
238-
239-
}
240-
241-
$result['tests'] = array_merge(
242-
$result['tests'],
243-
$testsInGroupAndNotInAnySuite
244-
);
245-
}
246-
247-
$json = json_encode($result);
248-
return $json;
249-
}
250191
}

0 commit comments

Comments
 (0)