@@ -41,26 +41,37 @@ class SuiteGenerator
41
41
*/
42
42
private $ groupClassGenerator ;
43
43
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
+
44
51
/**
45
52
* SuiteGenerator constructor.
53
+ *
54
+ * @param array $suiteReferences
46
55
*/
47
- private function __construct ()
56
+ private function __construct ($ suiteReferences )
48
57
{
49
58
$ this ->groupClassGenerator = new GroupClassGenerator ();
59
+ $ this ->suiteReferences = $ suiteReferences ;
50
60
}
51
61
52
62
/**
53
63
* Singleton method which is used to retrieve the instance of the suite generator.
54
64
*
65
+ * @param array $suiteReferences
55
66
* @return SuiteGenerator
56
67
*/
57
- public static function getInstance ()
68
+ public static function getInstance ($ suiteReferences = [] )
58
69
{
59
70
if (!self ::$ SUITE_GENERATOR_INSTANCE ) {
60
71
// clear any previous configurations before any generation occurs.
61
72
self ::clearPreviousGroupPreconditions ();
62
73
self ::clearPreviousSessionConfigEntries ();
63
- self ::$ SUITE_GENERATOR_INSTANCE = new SuiteGenerator ();
74
+ self ::$ SUITE_GENERATOR_INSTANCE = new SuiteGenerator ($ suiteReferences );
64
75
}
65
76
66
77
return self ::$ SUITE_GENERATOR_INSTANCE ;
@@ -79,6 +90,8 @@ public function generateAllSuites($testManifest)
79
90
if (get_class ($ testManifest ) == ParallelTestManifest::class) {
80
91
/** @var ParallelTestManifest $testManifest */
81
92
$ suites = $ testManifest ->getSorter ()->getResultingSuites ();
93
+ } elseif (!empty ($ this ->suiteReferences )) {
94
+ $ suites = array_intersect_key ($ suites , $ this ->suiteReferences );
82
95
}
83
96
84
97
foreach ($ suites as $ suite ) {
@@ -96,11 +109,22 @@ public function getTestsReferencedInSuites()
96
109
{
97
110
$ testsReferencedInSuites = [];
98
111
$ 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
+
99
118
foreach ($ suites as $ suite ) {
100
119
/** @var SuiteObject $suite */
101
120
$ test_keys = array_keys ($ suite ->getTests ());
102
- $ testToSuiteName = array_fill_keys ($ test_keys , [$ suite ->getName ()]);
103
121
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 ()]);
104
128
$ testsReferencedInSuites = array_merge_recursive ($ testsReferencedInSuites , $ testToSuiteName );
105
129
}
106
130
@@ -135,7 +159,19 @@ public function generateSuiteFromObject($suiteObject)
135
159
$ groupNamespace = null ;
136
160
137
161
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 );
139
175
140
176
if ($ suiteObject ->requiresGroupFile ()) {
141
177
// if the suite requires a group file, generate it and set the namespace
0 commit comments