Skip to content

Commit 9adb681

Browse files
authored
Merge pull request #119 from magento/MQE-985
MQE-985: Empty Suite configuration should not generate
2 parents 9aa35bf + 371680d commit 9adb681

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

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

+25
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

+19-5
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ public function parseSuiteDataIntoObjects($parsedSuiteData)
8989
$includeTests = $this->extractTestObjectsFromSuiteRef($groupTestsToInclude);
9090
$excludeTests = $this->extractTestObjectsFromSuiteRef($groupTestsToExclude);
9191

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

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

0 commit comments

Comments
 (0)