Skip to content

MQE-1059: When a single test is specified all suites should not generate #148

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 2 commits into from
Jun 14, 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 @@ -24,6 +24,13 @@ class ArrayNodeConfig
*/
private $assocArrays = [];

/**
* Flat array of expanded patterns for matching xpath
*
* @var array
*/
private $flatAssocArray = [];

/**
* Format: array('/numeric/array/path', ...)
*
Expand All @@ -44,6 +51,7 @@ public function __construct(
) {
$this->nodePathMatcher = $nodePathMatcher;
$this->assocArrays = $assocArrayAttributes;
$this->flatAssocArray = $this->flattenToAssocKeyAttributes($assocArrayAttributes);
$this->numericArrays = $numericArrays;
}

Expand Down Expand Up @@ -71,11 +79,68 @@ public function isNumericArray($nodeXpath)
*/
public function getAssocArrayKeyAttribute($nodeXpath)
{
if (array_key_exists($nodeXpath, $this->flatAssocArray)) {
return $this->flatAssocArray[$nodeXpath];
}

foreach ($this->assocArrays as $pathPattern => $keyAttribute) {
if ($this->nodePathMatcher->match($pathPattern, $nodeXpath)) {
return $keyAttribute;
}
}
return null;
}

/**
* Function which takes a patterned list of xpath matchers and flattens to a single level array for
* performance improvement
*
* @param array $assocArrayAttributes
* @return array
*/
private function flattenToAssocKeyAttributes($assocArrayAttributes)
{
$finalPatterns = [];
foreach ($assocArrayAttributes as $pattern => $key) {
$vars = explode("/", ltrim($pattern, "/"));
$stringPatterns = [""];
foreach ($vars as $var) {
if (strstr($var, "|")) {
$repOpen = str_replace("(", "", $var);
$repClosed = str_replace(")", "", $repOpen);
$nestedPatterns = explode("|", $repClosed);
$stringPatterns = $this->mergeStrings($stringPatterns, $nestedPatterns);
continue;
}

// append this path to all of the paths that currently exist
array_walk($stringPatterns, function (&$value, $key) use ($var) {
$value .= "/" . $var;
});
}

$finalPatterns = array_merge($finalPatterns, array_fill_keys($stringPatterns, $key));
}

return $finalPatterns;
}

/**
* Takes 2 arrays and appends all string in the second array to each entry in the first.
*
* @param string[] $parentStrings
* @param string[] $childStrings
* @return array
*/
private function mergeStrings($parentStrings, $childStrings)
{
$result = [];
foreach ($parentStrings as $pString) {
foreach ($childStrings as $cString) {
$result[] = $pString . "/" . $cString;
}
}

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$testManifest->createTestGroups($time);
}

SuiteGenerator::getInstance()->generateAllSuites($testManifest);
if (empty($tests)) {
SuiteGenerator::getInstance()->generateAllSuites($testManifest);
}

$testManifest->generate();

$output->writeln("Generate Tests Command Run");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function processParserOutput($parserOutput)
throw new XmlException(sprintf(self::DATA_NAME_ERROR_MSG, $name));
}

$type = $rawEntity[self::_TYPE];
$type = $rawEntity[self::_TYPE] ?? null;
$data = [];
$linkedEntities = [];
$uniquenessData = [];
Expand Down