Skip to content

MQE-985: Empty Suite configuration should not generate #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
use Magento\FunctionalTestingFramework\Suite\Parsers\SuiteDataParser;
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor;
use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser;
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -87,6 +88,30 @@ public function testGenerateAllSuites()
$this->expectOutputString("Suite basicTestSuite generated to _generated/basicTestSuite." . PHP_EOL);
}

/**
* Tests attempting to generate a suite with no included/excluded tests and no hooks
* @throws \Exception
*/
public function testGenerateEmptySuite()
{
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
$mockData = $suiteDataArrayBuilder
->withName('basicTestSuite')
->build();
unset($mockData['suites']['basicTestSuite'][TestObjectExtractor::TEST_BEFORE_HOOK]);
unset($mockData['suites']['basicTestSuite'][TestObjectExtractor::TEST_AFTER_HOOK]);

$mockTestData = null;
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);

// set expected error message
$this->expectExceptionMessage("Suites must not be empty. Suite: \"basicTestSuite\"");

// parse and generate suite object with mocked data
$mockSuiteGenerator = SuiteGenerator::getInstance();
$mockSuiteGenerator->generateSuite("basicTestSuite");
}

/**
* Function used to set mock for parser return and force init method to run between tests.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public function parseSuiteDataIntoObjects($parsedSuiteData)
$includeTests = $this->extractTestObjectsFromSuiteRef($groupTestsToInclude);
$excludeTests = $this->extractTestObjectsFromSuiteRef($groupTestsToExclude);

// add all test if include tests is completely empty
if (empty($includeTests)) {
$includeTests = TestObjectHandler::getInstance()->getAllObjects();
}

// parse any object hooks
if (array_key_exists(TestObjectExtractor::TEST_BEFORE_HOOK, $parsedSuite)) {
$suiteHooks[TestObjectExtractor::TEST_BEFORE_HOOK] = $testHookObjectExtractor->extractHook(
Expand All @@ -109,12 +104,31 @@ public function parseSuiteDataIntoObjects($parsedSuiteData)
$parsedSuite[TestObjectExtractor::TEST_AFTER_HOOK]
);
}

if (count($suiteHooks) == 1) {
throw new XmlException(sprintf(
"Suites that contain hooks must contain both a 'before' and an 'after' hook. Suite: \"%s\"",
$parsedSuite[self::NAME]
));
}
// check if suite hooks are empty/not included and there are no included tests/groups/modules
$noHooks = count($suiteHooks) == 0 ||
(
empty($suiteHooks['before']->getActions()) &&
empty($suiteHooks['after']->getActions())
);
// if suite body is empty throw error
if ($noHooks && empty($includeTests) && empty($excludeTests)) {
throw new XmlException(sprintf(
"Suites must not be empty. Suite: \"%s\"",
$parsedSuite[self::NAME]
));
}

// add all test if include tests is completely empty
if (empty($includeTests)) {
$includeTests = TestObjectHandler::getInstance()->getAllObjects();
}

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