Skip to content

Commit c204f13

Browse files
committed
MQE-893: Add flag to robo generate: tests which accepts a specific set of tests to execute
- alter SuiteGenerator to account for custom suite configuration
1 parent 734f356 commit c204f13

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,37 @@ class SuiteGenerator
4141
*/
4242
private $groupClassGenerator;
4343

44+
/**
45+
* Multidimensional array which represents a custom suite configuration (e.g. certain tests run within a suite etc.)
46+
*
47+
* @var array
48+
*/
49+
private $suiteReferences;
50+
4451
/**
4552
* SuiteGenerator constructor.
53+
*
54+
* @param array $suiteReferences
4655
*/
47-
private function __construct()
56+
private function __construct($suiteReferences)
4857
{
4958
$this->groupClassGenerator = new GroupClassGenerator();
59+
$this->suiteReferences = $suiteReferences;
5060
}
5161

5262
/**
5363
* Singleton method which is used to retrieve the instance of the suite generator.
5464
*
65+
* @param array $suiteReferences
5566
* @return SuiteGenerator
5667
*/
57-
public static function getInstance()
68+
public static function getInstance($suiteReferences = [])
5869
{
5970
if (!self::$SUITE_GENERATOR_INSTANCE) {
6071
// clear any previous configurations before any generation occurs.
6172
self::clearPreviousGroupPreconditions();
6273
self::clearPreviousSessionConfigEntries();
63-
self::$SUITE_GENERATOR_INSTANCE = new SuiteGenerator();
74+
self::$SUITE_GENERATOR_INSTANCE = new SuiteGenerator($suiteReferences);
6475
}
6576

6677
return self::$SUITE_GENERATOR_INSTANCE;
@@ -79,6 +90,8 @@ public function generateAllSuites($testManifest)
7990
if (get_class($testManifest) == ParallelTestManifest::class) {
8091
/** @var ParallelTestManifest $testManifest */
8192
$suites = $testManifest->getSorter()->getResultingSuites();
93+
} elseif (!empty($this->suiteReferences)) {
94+
$suites = array_intersect_key($suites, $this->suiteReferences);
8295
}
8396

8497
foreach ($suites as $suite) {
@@ -96,11 +109,22 @@ public function getTestsReferencedInSuites()
96109
{
97110
$testsReferencedInSuites = [];
98111
$suites = SuiteObjectHandler::getInstance()->getAllObjects();
112+
113+
// see if we have a specific suite configuration.
114+
if (!empty($this->suiteReferences)) {
115+
$suites = array_intersect_key($suites, $this->suiteReferences);
116+
}
117+
99118
foreach ($suites as $suite) {
100119
/** @var SuiteObject $suite */
101120
$test_keys = array_keys($suite->getTests());
102-
$testToSuiteName = array_fill_keys($test_keys, [$suite->getName()]);
103121

122+
// see if we need to filter which tests we'll be generating.
123+
if (array_key_exists($suite->getName(), $this->suiteReferences)) {
124+
$test_keys = $this->suiteReferences[$suite->getName()] ?? $test_keys;
125+
}
126+
127+
$testToSuiteName = array_fill_keys($test_keys, [$suite->getName()]);
104128
$testsReferencedInSuites = array_merge_recursive($testsReferencedInSuites, $testToSuiteName);
105129
}
106130

@@ -135,7 +159,19 @@ public function generateSuiteFromObject($suiteObject)
135159
$groupNamespace = null;
136160

137161
DirSetupUtil::createGroupDir($fullPath);
138-
$this->generateRelevantGroupTests($suiteName, $suiteObject->getTests());
162+
163+
$relevantTests = $suiteObject->getTests();
164+
if (array_key_exists($suiteName, $this->suiteReferences)) {
165+
$testReferences = $this->suiteReferences[$suiteName] ?? [];
166+
$tmpRelevantTests = null;
167+
array_walk($testReferences, function ($value) use (&$tmpRelevantTests, $relevantTests) {
168+
$tmpRelevantTests[$value] = $relevantTests[$value];
169+
});
170+
171+
$relevantTests = $tmpRelevantTests ?? $relevantTests;
172+
}
173+
174+
$this->generateRelevantGroupTests($suiteName, $relevantTests);
139175

140176
if ($suiteObject->requiresGroupFile()) {
141177
// if the suite requires a group file, generate it and set the namespace

0 commit comments

Comments
 (0)