From 5bdd3d2257eefa125be9bcec474a685297d688b9 Mon Sep 17 00:00:00 2001 From: Ian Meron Date: Wed, 13 Jun 2018 09:28:27 -0500 Subject: [PATCH] MQE-1059: When a single test is specified all suites should not generate - add logic to flatten assoc array and wrap suite generation in conditional logic --- .../Config/Dom/ArrayNodeConfig.php | 65 +++++++++++++++++++ .../Console/GenerateTestsCommand.php | 5 +- .../Handlers/DataObjectHandler.php | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Config/Dom/ArrayNodeConfig.php b/src/Magento/FunctionalTestingFramework/Config/Dom/ArrayNodeConfig.php index eaa216649..8bb06376a 100644 --- a/src/Magento/FunctionalTestingFramework/Config/Dom/ArrayNodeConfig.php +++ b/src/Magento/FunctionalTestingFramework/Config/Dom/ArrayNodeConfig.php @@ -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', ...) * @@ -44,6 +51,7 @@ public function __construct( ) { $this->nodePathMatcher = $nodePathMatcher; $this->assocArrays = $assocArrayAttributes; + $this->flatAssocArray = $this->flattenToAssocKeyAttributes($assocArrayAttributes); $this->numericArrays = $numericArrays; } @@ -71,6 +79,10 @@ 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; @@ -78,4 +90,57 @@ public function getAssocArrayKeyAttribute($nodeXpath) } 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; + } } diff --git a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php index 119fe48f9..d9ef5dea5 100644 --- a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php @@ -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"); diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php index 5dc9293c2..9ab14e5ff 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php @@ -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 = [];