Skip to content

Commit 94e9124

Browse files
committed
MQE-985: Empty Suite configuration should not generate
- Adding check for empty suites
1 parent 5ca48e1 commit 94e9124

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
1414
use Magento\FunctionalTestingFramework\Suite\Parsers\SuiteDataParser;
1515
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
16+
use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor;
1617
use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser;
1718
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
1819
use PHPUnit\Framework\TestCase;
@@ -87,6 +88,30 @@ public function testGenerateAllSuites()
8788
$this->expectOutputString("Suite basicTestSuite generated to _generated/basicTestSuite." . PHP_EOL);
8889
}
8990

91+
/**
92+
* Tests attempting to generate a suite with no included/excluded tests and no hooks
93+
* @throws \Exception
94+
*/
95+
public function testGenerateEmptySuite()
96+
{
97+
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
98+
$mockData = $suiteDataArrayBuilder
99+
->withName('basicTestSuite')
100+
->build();
101+
unset($mockData['suites']['basicTestSuite'][TestObjectExtractor::TEST_BEFORE_HOOK]);
102+
unset($mockData['suites']['basicTestSuite'][TestObjectExtractor::TEST_AFTER_HOOK]);
103+
104+
$mockTestData = null;
105+
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);
106+
107+
// set expected error message
108+
$this->expectExceptionMessage("Suites must not be empty. Suite: \"basicTestSuite\"");
109+
110+
// parse and generate suite object with mocked data
111+
$mockSuiteGenerator = SuiteGenerator::getInstance();
112+
$mockSuiteGenerator->generateSuite("basicTestSuite");
113+
}
114+
90115
/**
91116
* Function used to set mock for parser return and force init method to run between tests.
92117
*

src/Magento/FunctionalTestingFramework/Suite/Util/SuiteObjectExtractor.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ public function parseSuiteDataIntoObjects($parsedSuiteData)
8888
$includeTests = $this->extractTestObjectsFromSuiteRef($groupTestsToInclude);
8989
$excludeTests = $this->extractTestObjectsFromSuiteRef($groupTestsToExclude);
9090

91-
// add all test if include tests is completely empty
92-
if (empty($includeTests)) {
93-
$includeTests = TestObjectHandler::getInstance()->getAllObjects();
94-
}
95-
9691
// parse any object hooks
9792
if (array_key_exists(TestObjectExtractor::TEST_BEFORE_HOOK, $parsedSuite)) {
9893
$suiteHooks[TestObjectExtractor::TEST_BEFORE_HOOK] = $testHookObjectExtractor->extractHook(
@@ -108,12 +103,31 @@ public function parseSuiteDataIntoObjects($parsedSuiteData)
108103
$parsedSuite[TestObjectExtractor::TEST_AFTER_HOOK]
109104
);
110105
}
106+
111107
if (count($suiteHooks) == 1) {
112108
throw new XmlException(sprintf(
113109
"Suites that contain hooks must contain both a 'before' and an 'after' hook. Suite: \"%s\"",
114110
$parsedSuite[self::NAME]
115111
));
116112
}
113+
// check if suite hooks are empty/not included and there are no included tests/groups/modules
114+
$noHooks = count($suiteHooks) == 0 ||
115+
(
116+
empty($suiteHooks['before']->getActions()) &&
117+
empty($suiteHooks['after']->getActions())
118+
);
119+
// if suite body is empty throw error
120+
if ($noHooks && empty($includeTests) && empty($excludeTests)) {
121+
throw new XmlException(sprintf(
122+
"Suites must not be empty. Suite: \"%s\"",
123+
$parsedSuite[self::NAME]
124+
));
125+
}
126+
127+
// add all test if include tests is completely empty
128+
if (empty($includeTests)) {
129+
$includeTests = TestObjectHandler::getInstance()->getAllObjects();
130+
}
117131

118132
// create the new suite object
119133
$suiteObjects[$parsedSuite[self::NAME]] = new SuiteObject(

0 commit comments

Comments
 (0)