Skip to content

Commit 4f847dd

Browse files
committed
MQE-893: Add flag to robo generate: tests which accepts a specific set of tests to execute
- fix generation error during non custom generation - fix multidimensional references issue
1 parent 1e8fbd3 commit 4f847dd

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

src/Magento/FunctionalTestingFramework/Util/Manifest/ParallelTestManifest.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
1515
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
1616
use Magento\FunctionalTestingFramework\Util\Sorter\ParallelGroupSorter;
17+
use RecursiveArrayIterator;
18+
use RecursiveIteratorIterator;
1719

1820
class ParallelTestManifest extends BaseTestManifest
1921
{
@@ -97,9 +99,10 @@ public function createTestGroups($lines)
9799
public function generate()
98100
{
99101
DirSetupUtil::createGroupDir($this->dirPath);
102+
$suites = $this->getFlattenedSuiteConfiguration($this->parallelGroupSorter->getResultingSuiteConfig());
100103

101104
foreach ($this->testGroups as $groupNumber => $groupContents) {
102-
$this->generateGroupFile($groupContents, $groupNumber);
105+
$this->generateGroupFile($groupContents, $groupNumber, $suites);
103106
}
104107
}
105108

@@ -115,15 +118,16 @@ public function getSorter()
115118

116119
/**
117120
* Function which takes an array containing entries representing the test execution as well as the associated group
118-
* for the entry in order to generate a txt file used by devops for parllel execution in Jenkins.
121+
* for the entry in order to generate a txt file used by devops for parllel execution in Jenkins. The results
122+
* are checked against a flattened list of suites in order to generate proper entries.
119123
*
120124
* @param array $testGroup
121125
* @param int $nodeNumber
126+
* @param array $suites
122127
* @return void
123128
*/
124-
private function generateGroupFile($testGroup, $nodeNumber)
129+
private function generateGroupFile($testGroup, $nodeNumber, $suites)
125130
{
126-
$suites = $this->parallelGroupSorter->getResultingSuiteConfig();
127131
foreach ($testGroup as $entryName => $testValue) {
128132
$fileResource = fopen($this->dirPath . DIRECTORY_SEPARATOR . "group{$nodeNumber}.txt", 'a');
129133

@@ -137,4 +141,27 @@ private function generateGroupFile($testGroup, $nodeNumber)
137141
fclose($fileResource);
138142
}
139143
}
144+
145+
/**
146+
* Function which recusrively parses a given potentially multidimensional array of suites containing their split
147+
* groups. The result is a flattened array of suite names to relevant tests for generation of the manifest.
148+
*
149+
* @param array $multiDimensionalSuites
150+
* @return array
151+
*/
152+
private function getFlattenedSuiteConfiguration($multiDimensionalSuites)
153+
{
154+
$suites = [];
155+
foreach ($multiDimensionalSuites as $suiteName => $suiteContent) {
156+
$value = array_values($suiteContent)[0];
157+
if (is_array($value)) {
158+
$suites = array_merge($suites, $this->getFlattenedSuiteConfiguration($suiteContent));
159+
continue;
160+
}
161+
162+
$suites[$suiteName] = $suiteContent;
163+
}
164+
165+
return $suites;
166+
}
140167
}

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,28 @@ public function getExportDir()
113113
}
114114

115115
/**
116-
* Load all Test files as Objects using the Test Object Handler.
116+
* Load all Test files as Objects using the Test Object Handler, additionally validates test references being loaded
117+
* for validity.
117118
*
119+
* @param array $testsToIgnore
118120
* @return array
119121
*/
120-
private function loadAllTestObjects()
122+
private function loadAllTestObjects($testsToIgnore)
121123
{
122124
if ($this->tests === null || empty($this->tests)) {
123-
return TestObjectHandler::getInstance()->getAllObjects();
125+
$testObjects = TestObjectHandler::getInstance()->getAllObjects();
126+
return array_diff_key($testObjects, $testsToIgnore);
127+
}
128+
129+
// If we have a custom configuration, we need to check the tests passed in to insure that we can generate
130+
// them in the current context.
131+
$invalidTestObjects = array_intersect_key($this->tests, $testsToIgnore);
132+
if (!empty($invalidTestObjects)) {
133+
$errorMsg = "Cannot reference the following tests for generation without accompanying suite:\n";
134+
array_walk($invalidTestObjects, function ($value, $key) use (&$errorMsg) {
135+
$errorMsg.= "\t{$key}\n";
136+
});
137+
throw new TestReferenceException($errorMsg);
124138
}
125139

126140
return $this->tests;
@@ -216,19 +230,7 @@ private function assembleTestPhp($testObject)
216230
private function assembleAllTestPhp($testManifest, array $testsToIgnore)
217231
{
218232
/** @var TestObject[] $testObjects */
219-
$testObjects = $this->loadAllTestObjects();
220-
221-
// We need to check the tests passed in to insure that we can generate them in the current context.
222-
$invalidTestObjects = array_intersect_key($testObjects, $testsToIgnore);
223-
if (!empty($invalidTestObjects)) {
224-
$errorMsg = "Cannot reference the following tests for generation without accompanying suite:\n";
225-
array_walk($invalidTestObjects, function ($value, $key) use (&$errorMsg) {
226-
$errorMsg.= "\t{$key}\n";
227-
});
228-
throw new TestReferenceException($errorMsg);
229-
}
230-
231-
$testObjects = array_diff_key($testObjects, $testsToIgnore);
233+
$testObjects = $this->loadAllTestObjects($testsToIgnore);
232234
$cestPhpArray = [];
233235

234236
foreach ($testObjects as $test) {

0 commit comments

Comments
 (0)