8
8
9
9
use Magento \Framework \Module \Dir ;
10
10
use Magento \FunctionalTestingFramework \Suite \SuiteGenerator ;
11
- use Magento \FunctionalTestingFramework \Util \TestManifest ;
11
+ use Magento \FunctionalTestingFramework \Util \Filesystem \DirSetupUtil ;
12
+ use Magento \FunctionalTestingFramework \Util \Manifest \ParallelTestManifest ;
13
+ use Magento \FunctionalTestingFramework \Util \Manifest \TestManifestFactory ;
12
14
use Symfony \Component \Yaml \Yaml ;
13
15
use tests \util \MftfTestCase ;
14
16
15
17
class SuiteGenerationTest extends MftfTestCase
16
18
{
17
19
const RESOURCES_DIR = TESTS_BP . DIRECTORY_SEPARATOR . 'verification ' . DIRECTORY_SEPARATOR . 'Resources ' ;
18
20
const CONFIG_YML_FILE = FW_BP . DIRECTORY_SEPARATOR . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME ;
21
+ const GENERATE_RESULT_DIR = TESTS_BP .
22
+ DIRECTORY_SEPARATOR .
23
+ "verification " .
24
+ DIRECTORY_SEPARATOR .
25
+ "_generated " .
26
+ DIRECTORY_SEPARATOR ;
19
27
20
28
/**
21
29
* Flag to track existence of config.yml file
@@ -75,11 +83,94 @@ public function testSuiteGeneration1()
75
83
$ yml = Yaml::parse (file_get_contents (self ::CONFIG_YML_FILE ));
76
84
$ this ->assertArrayHasKey ($ groupName , $ yml ['groups ' ]);
77
85
78
- $ suiteResultBaseDir = TESTS_BP .
86
+ $ suiteResultBaseDir = self :: GENERATE_RESULT_DIR .
79
87
DIRECTORY_SEPARATOR .
80
- "verification " .
81
- DIRECTORY_SEPARATOR .
82
- "_generated " .
88
+ $ groupName .
89
+ DIRECTORY_SEPARATOR ;
90
+
91
+ // Validate tests have been generated
92
+ $ dirContents = array_diff (scandir ($ suiteResultBaseDir ), ['.. ' , '. ' ]);
93
+
94
+ foreach ($ expectedContents as $ expectedFile ) {
95
+ $ this ->assertTrue (in_array ($ expectedFile , $ dirContents ));
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Test generation of parallel suite groups
101
+ */
102
+ public function testSuiteGenerationParallel ()
103
+ {
104
+ $ groupName = 'functionalSuite1 ' ;
105
+
106
+ $ expectedGroups = [
107
+ 'functionalSuite1_0 ' ,
108
+ 'functionalSuite1_1 ' ,
109
+ 'functionalSuite1_2 ' ,
110
+ 'functionalSuite1_3 '
111
+ ];
112
+
113
+ $ expectedContents = [
114
+ 'additionalTestCest.php ' ,
115
+ 'additionalIncludeTest2Cest.php ' ,
116
+ 'IncludeTest2Cest.php ' ,
117
+ 'IncludeTestCest.php '
118
+ ];
119
+
120
+ //createParallelManifest
121
+ /** @var ParallelTestManifest $parallelManifest */
122
+ $ parallelManifest = TestManifestFactory::makeManifest ("parallel " , ["functionalSuite1 " => []]);
123
+
124
+ // Generate the Suite
125
+ $ parallelManifest ->createTestGroups (1 );
126
+ SuiteGenerator::getInstance ()->generateAllSuites ($ parallelManifest );
127
+
128
+ // Validate console message and add group name for later deletion
129
+ $ this ->expectOutputRegex ('/Suite .* generated to .*/ ' );
130
+ self ::$ TEST_GROUPS [] = $ groupName ;
131
+
132
+ // Validate Yaml file updated
133
+ $ yml = Yaml::parse (file_get_contents (self ::CONFIG_YML_FILE ));
134
+ $ this ->assertEquals ($ expectedGroups , array_keys ($ yml ['groups ' ]));
135
+
136
+ foreach ($ expectedGroups as $ expectedFolder ) {
137
+ $ suiteResultBaseDir = self ::GENERATE_RESULT_DIR .
138
+ DIRECTORY_SEPARATOR .
139
+ $ expectedFolder .
140
+ DIRECTORY_SEPARATOR ;
141
+
142
+ // Validate tests have been generated
143
+ $ dirContents = array_diff (scandir ($ suiteResultBaseDir ), ['.. ' , '. ' ]);
144
+
145
+ //Validate only one test has been added to each group since lines are set to 1
146
+ $ this ->assertEquals (1 , count ($ dirContents ));
147
+ $ this ->assertContains (array_values ($ dirContents )[0 ], $ expectedContents );
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Test hook groups generated during suite generation
153
+ */
154
+ public function testSuiteGenerationHooks ()
155
+ {
156
+ $ groupName = 'functionalSuiteHooks ' ;
157
+
158
+ $ expectedContents = [
159
+ 'IncludeTestCest.php '
160
+ ];
161
+
162
+ // Generate the Suite
163
+ SuiteGenerator::getInstance ()->generateSuite ($ groupName );
164
+
165
+ // Validate console message and add group name for later deletion
166
+ $ this ->expectOutputRegex ('/Suite .* generated to .*/ ' );
167
+ self ::$ TEST_GROUPS [] = $ groupName ;
168
+
169
+ // Validate Yaml file updated
170
+ $ yml = Yaml::parse (file_get_contents (self ::CONFIG_YML_FILE ));
171
+ $ this ->assertArrayHasKey ($ groupName , $ yml ['groups ' ]);
172
+
173
+ $ suiteResultBaseDir = self ::GENERATE_RESULT_DIR .
83
174
DIRECTORY_SEPARATOR .
84
175
$ groupName .
85
176
DIRECTORY_SEPARATOR ;
@@ -90,25 +181,55 @@ public function testSuiteGeneration1()
90
181
foreach ($ expectedContents as $ expectedFile ) {
91
182
$ this ->assertTrue (in_array ($ expectedFile , $ dirContents ));
92
183
}
184
+
185
+ //assert group file created and contains correct contents
186
+ $ groupFile = PROJECT_ROOT .
187
+ DIRECTORY_SEPARATOR .
188
+ "src " .
189
+ DIRECTORY_SEPARATOR .
190
+ "Magento " .
191
+ DIRECTORY_SEPARATOR .
192
+ "FunctionalTestingFramework " .
193
+ DIRECTORY_SEPARATOR .
194
+ "Group " .
195
+ DIRECTORY_SEPARATOR .
196
+ $ groupName .
197
+ ".php " ;
198
+
199
+ $ this ->assertTrue (file_exists ($ groupFile ));
200
+ $ this ->assertFileEquals (
201
+ self ::RESOURCES_PATH . DIRECTORY_SEPARATOR . $ groupName . ".txt " ,
202
+ $ groupFile
203
+ );
204
+
93
205
}
94
206
95
207
/**
96
208
* revert any changes made to config.yml
209
+ * remove _generated directory
97
210
*/
98
- public static function tearDownAfterClass ()
211
+ public function tearDown ()
99
212
{
100
213
// restore config if we see there was an original codeception.yml file
101
214
if (self ::$ YML_EXISTS_FLAG ) {
102
215
$ yml = Yaml::parse (file_get_contents (self ::CONFIG_YML_FILE ));
103
216
foreach (self ::$ TEST_GROUPS as $ testGroup ) {
104
- unset($ yml ['group ' ][$ testGroup ]);
217
+ unset($ yml ['groups ' ][$ testGroup ]);
105
218
}
106
219
107
220
file_put_contents (self ::CONFIG_YML_FILE , Yaml::dump ($ yml , 10 ));
108
- return ;
109
221
}
222
+ DirSetupUtil::rmdirRecursive (self ::GENERATE_RESULT_DIR );
223
+ }
110
224
111
- unlink (self ::CONFIG_YML_FILE );
225
+ /**
226
+ * Remove yml if created during tests and did not exist before
227
+ */
228
+ public static function tearDownAfterClass ()
229
+ {
230
+ if (!self ::$ YML_EXISTS_FLAG ) {
231
+ unlink (self ::CONFIG_YML_FILE );
232
+ }
112
233
}
113
234
114
235
/**
0 commit comments