Skip to content

Commit b7ee3f8

Browse files
committed
Work in progress before vacation
1 parent 365daa2 commit b7ee3f8

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function ($type, $buffer) use ($output) {
119119
* @return string
120120
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
121121
*/
122-
private function getGroupAndSuiteConfiguration(array $groups)
122+
private function OLDgetGroupAndSuiteConfiguration(array $groups)
123123
{
124124
$testConfiguration['tests'] = [];
125125
$testConfiguration['suites'] = null;
@@ -139,4 +139,112 @@ private function getGroupAndSuiteConfiguration(array $groups)
139139
$testConfigurationJson = json_encode($testConfiguration);
140140
return $testConfigurationJson;
141141
}
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+
}
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+
}
142250
}

0 commit comments

Comments
 (0)