16
16
use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
17
17
use Magento \FunctionalTestingFramework \Test \Util \TestObjectExtractor ;
18
18
use Magento \FunctionalTestingFramework \Test \Parsers \TestDataParser ;
19
+ use Magento \FunctionalTestingFramework \Util \GenerationErrorHandler ;
19
20
use Magento \FunctionalTestingFramework \Util \Manifest \DefaultTestManifest ;
20
21
use tests \unit \Util \MagentoTestCase ;
21
22
use Magento \FunctionalTestingFramework \Util \Manifest \TestManifestFactory ;
@@ -50,7 +51,6 @@ public function setUp(): void
50
51
51
52
/**
52
53
* Tests generating a single suite given a set of parsed test data
53
- * @throws \Exception
54
54
*/
55
55
public function testGenerateSuite ()
56
56
{
@@ -86,7 +86,6 @@ public function testGenerateSuite()
86
86
87
87
/**
88
88
* Tests generating all suites given a set of parsed test data
89
- * @throws \Exception
90
89
*/
91
90
public function testGenerateAllSuites ()
92
91
{
@@ -123,28 +122,36 @@ public function testGenerateAllSuites()
123
122
124
123
/**
125
124
* Tests attempting to generate a suite with no included/excluded tests and no hooks
126
- * @throws \Exception
127
125
*/
128
126
public function testGenerateEmptySuite ()
129
127
{
128
+ $ testDataArrayBuilder = new TestDataArrayBuilder ();
129
+ $ mockTestData = $ testDataArrayBuilder
130
+ ->withName ('test ' )
131
+ ->withAnnotations ()
132
+ ->withTestActions ()
133
+ ->build ();
134
+
130
135
$ suiteDataArrayBuilder = new SuiteDataArrayBuilder ();
131
136
$ mockData = $ suiteDataArrayBuilder
132
137
->withName ('basicTestSuite ' )
133
138
->build ();
134
139
unset($ mockData ['suites ' ]['basicTestSuite ' ][TestObjectExtractor::TEST_BEFORE_HOOK ]);
135
140
unset($ mockData ['suites ' ]['basicTestSuite ' ][TestObjectExtractor::TEST_AFTER_HOOK ]);
136
141
137
- $ mockTestData = null ;
138
142
$ this ->setMockTestAndSuiteParserOutput ($ mockTestData , $ mockData );
139
143
140
144
// set expected error message
141
- $ this ->expectExceptionMessage ("Suites must not be empty. Suite: \" basicTestSuite \" " );
145
+ $ this ->expectExceptionMessage ("Suite basicTestSuite is not defined in xml or is invalid " );
142
146
143
147
// parse and generate suite object with mocked data
144
148
$ mockSuiteGenerator = SuiteGenerator::getInstance ();
145
149
$ mockSuiteGenerator ->generateSuite ("basicTestSuite " );
146
150
}
147
151
152
+ /**
153
+ * Tests generating all suites with a suite containing invalid test reference
154
+ */
148
155
public function testInvalidSuiteTestPair ()
149
156
{
150
157
// Mock Suite1 => Test1 and Suite2 => Test2
@@ -179,15 +186,20 @@ public function testInvalidSuiteTestPair()
179
186
$ suiteConfig = ['Suite2 ' => ['Test1 ' ]];
180
187
$ manifest = TestManifestFactory::makeManifest ('default ' , $ suiteConfig );
181
188
182
- // Set up Expected Exception
183
- $ this ->expectException (TestReferenceException::class);
184
- $ this ->expectExceptionMessageMatches ('(Suite: "Suite2" Tests: "Test1") ' );
185
-
186
189
// parse and generate suite object with mocked data and manifest
187
190
$ mockSuiteGenerator = SuiteGenerator::getInstance ();
188
191
$ mockSuiteGenerator ->generateAllSuites ($ manifest );
192
+
193
+ // assert that no exception for generateAllSuites and suite generation error is stored in GenerationErrorHandler
194
+ $ errMessage = 'Cannot reference tests which are not declared as part of suite (Suite: "Suite2" Tests: "Test1") ' ;
195
+ TestLoggingUtil::getInstance ()->validateMockLogStatement ('error ' , $ errMessage , []);
196
+ $ suiteErrors = GenerationErrorHandler::getInstance ()->getErrorsByType ('suite ' );
197
+ $ this ->assertArrayHasKey ('Suite2 ' , $ suiteErrors );
189
198
}
190
199
200
+ /**
201
+ * Tests generating all suites with a non-existing suite
202
+ */
191
203
public function testNonExistentSuiteTestPair ()
192
204
{
193
205
$ testDataArrayBuilder = new TestDataArrayBuilder ();
@@ -203,19 +215,22 @@ public function testNonExistentSuiteTestPair()
203
215
$ suiteConfig = ['Suite3 ' => ['Test1 ' ]];
204
216
$ manifest = TestManifestFactory::makeManifest ('default ' , $ suiteConfig );
205
217
206
- // Set up Expected Exception
207
- $ this ->expectException (TestReferenceException::class);
208
- $ this ->expectExceptionMessageMatches ('#Suite3 is not defined# ' );
209
-
210
218
// parse and generate suite object with mocked data and manifest
211
219
$ mockSuiteGenerator = SuiteGenerator::getInstance ();
212
220
$ mockSuiteGenerator ->generateAllSuites ($ manifest );
221
+
222
+ // assert that no exception for generateAllSuites and suite generation error is stored in GenerationErrorHandler
223
+ $ errMessage = 'Suite Suite3 is not defined in xml or is invalid. ' ;
224
+ TestLoggingUtil::getInstance ()->validateMockLogStatement ('error ' , $ errMessage , []);
225
+ $ suiteErrors = GenerationErrorHandler::getInstance ()->getErrorsByType ('suite ' );
226
+ $ this ->assertArrayHasKey ('Suite3 ' , $ suiteErrors );
213
227
}
214
228
215
229
/**
216
230
* Function used to set mock for parser return and force init method to run between tests.
217
231
*
218
232
* @param array $testData
233
+ * @param array $suiteData
219
234
* @throws \Exception
220
235
*/
221
236
private function setMockTestAndSuiteParserOutput ($ testData , $ suiteData )
@@ -271,6 +286,14 @@ private function setMockTestAndSuiteParserOutput($testData, $suiteData)
271
286
$ property ->setValue ($ instance , $ instance );
272
287
}
273
288
289
+ /**
290
+ * clean up function runs after each test
291
+ */
292
+ public function tearDown (): void
293
+ {
294
+ GenerationErrorHandler::getInstance ()->reset ();
295
+ }
296
+
274
297
/**
275
298
* clean up function runs after all tests
276
299
*/
0 commit comments