@@ -162,7 +162,7 @@ public function testAllowSkipped(): void
162162 * @return void
163163 * @throws TestReferenceException
164164 */
165- public function testFilter (): void
165+ public function testSeverityFilter (): void
166166 {
167167 $ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
168168 $ fileList = new FilterList (['severity ' => ['CRITICAL ' ]]);
@@ -221,6 +221,136 @@ function ($filename) use (&$generatedTests) {
221221 $ this ->assertArrayNotHasKey ('test2Cest ' , $ generatedTests );
222222 }
223223
224+ /**
225+ * Tests that TestGenerator createAllTestFiles correctly filters based on group.
226+ *
227+ * @return void
228+ * @throws TestReferenceException
229+ */
230+ public function testIncludeGroupFilter (): void
231+ {
232+ $ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
233+ $ fileList = new FilterList (['includeGroup ' => ['someGroupValue ' ]]);
234+ $ mockConfig
235+ ->method ('getFilterList ' )
236+ ->willReturn ($ fileList );
237+
238+ $ property = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
239+ $ property ->setAccessible (true );
240+ $ property ->setValue ($ mockConfig );
241+
242+ $ actionInput = 'fakeInput ' ;
243+ $ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
244+ 'userInput ' => $ actionInput
245+ ]);
246+
247+ $ annotation1 = ['group ' => ['someGroupValue ' ]];
248+ $ annotation2 = ['group ' => ['someOtherGroupValue ' ]];
249+ $ test1 = new TestObject (
250+ 'test1 ' ,
251+ ['fakeAction ' => $ actionObject ],
252+ $ annotation1 ,
253+ [],
254+ 'filename '
255+ );
256+ $ test2 = new TestObject (
257+ 'test2 ' ,
258+ ['fakeAction ' => $ actionObject ],
259+ $ annotation2 ,
260+ [],
261+ 'filename '
262+ );
263+
264+ // Mock createCestFile to return name of tests that testGenerator tried to create
265+ $ generatedTests = [];
266+ $ cestFileCreatorUtil = $ this ->createMock (CestFileCreatorUtil::class);
267+ $ cestFileCreatorUtil
268+ ->method ('create ' )
269+ ->will (
270+ $ this ->returnCallback (
271+ function ($ filename ) use (&$ generatedTests ) {
272+ $ generatedTests [$ filename ] = true ;
273+ }
274+ )
275+ );
276+
277+ $ property = new ReflectionProperty (CestFileCreatorUtil::class, 'INSTANCE ' );
278+ $ property ->setAccessible (true );
279+ $ property ->setValue ($ cestFileCreatorUtil );
280+
281+ $ testGeneratorObject = TestGenerator::getInstance ('' , ['sampleTest ' => $ test1 , 'test2 ' => $ test2 ]);
282+ $ testGeneratorObject ->createAllTestFiles ();
283+
284+ // Ensure Test1 was Generated but not Test 2
285+ $ this ->assertArrayHasKey ('test1Cest ' , $ generatedTests );
286+ $ this ->assertArrayNotHasKey ('test2Cest ' , $ generatedTests );
287+ }
288+
289+ /**
290+ * Tests that TestGenerator createAllTestFiles correctly filters based on group not included.
291+ *
292+ * @return void
293+ * @throws TestReferenceException
294+ */
295+ public function testExcludeGroupFilter (): void
296+ {
297+ $ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
298+ $ fileList = new FilterList (['excludeGroup ' => ['someGroupValue ' ]]);
299+ $ mockConfig
300+ ->method ('getFilterList ' )
301+ ->willReturn ($ fileList );
302+
303+ $ property = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
304+ $ property ->setAccessible (true );
305+ $ property ->setValue ($ mockConfig );
306+
307+ $ actionInput = 'fakeInput ' ;
308+ $ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
309+ 'userInput ' => $ actionInput
310+ ]);
311+
312+ $ annotation1 = ['group ' => ['someGroupValue ' ]];
313+ $ annotation2 = ['group ' => ['someOtherGroupValue ' ]];
314+ $ test1 = new TestObject (
315+ 'test1 ' ,
316+ ['fakeAction ' => $ actionObject ],
317+ $ annotation1 ,
318+ [],
319+ 'filename '
320+ );
321+ $ test2 = new TestObject (
322+ 'test2 ' ,
323+ ['fakeAction ' => $ actionObject ],
324+ $ annotation2 ,
325+ [],
326+ 'filename '
327+ );
328+
329+ // Mock createCestFile to return name of tests that testGenerator tried to create
330+ $ generatedTests = [];
331+ $ cestFileCreatorUtil = $ this ->createMock (CestFileCreatorUtil::class);
332+ $ cestFileCreatorUtil
333+ ->method ('create ' )
334+ ->will (
335+ $ this ->returnCallback (
336+ function ($ filename ) use (&$ generatedTests ) {
337+ $ generatedTests [$ filename ] = true ;
338+ }
339+ )
340+ );
341+
342+ $ property = new ReflectionProperty (CestFileCreatorUtil::class, 'INSTANCE ' );
343+ $ property ->setAccessible (true );
344+ $ property ->setValue ($ cestFileCreatorUtil );
345+
346+ $ testGeneratorObject = TestGenerator::getInstance ('' , ['sampleTest ' => $ test1 , 'test2 ' => $ test2 ]);
347+ $ testGeneratorObject ->createAllTestFiles ();
348+
349+ // Ensure Test2 was Generated but not Test 1
350+ $ this ->assertArrayNotHasKey ('test1Cest ' , $ generatedTests );
351+ $ this ->assertArrayHasKey ('test2Cest ' , $ generatedTests );
352+ }
353+
224354 /**
225355 * @inheritDoc
226356 */
0 commit comments