Skip to content

Commit 37ea58d

Browse files
committed
MQE-1561: CreateData action must be able to parse Data entity which references another data
- fix static check failures
1 parent bec1456 commit 37ea58d

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/EntityDataObject.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ class EntityDataObject
8282
/**
8383
* Constructor
8484
*
85-
* @param string $name
86-
* @param string $type
85+
* @param string $name
86+
* @param string $type
8787
* @param string[] $data
8888
* @param string[] $linkedEntities
8989
* @param string[] $uniquenessData
9090
* @param string[] $vars
91-
* @param string $parentEntity
92-
* @param string $filename
91+
* @param string $parentEntity
92+
* @param string $filename
9393
*/
9494
public function __construct(
9595
$name,
@@ -161,6 +161,7 @@ public function getAllData()
161161
* @param integer $uniquenessFormat
162162
* @return string|null
163163
* @throws TestFrameworkException
164+
* @SuppressWarnings(PHPMD)
164165
*/
165166
public function getDataByName($name, $uniquenessFormat)
166167
{

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/OperationDataArrayResolver.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public function __construct($dependentEntities = null)
6666
* @param boolean $fromArray
6767
* @return array
6868
* @throws \Exception
69-
* @SuppressWarnings(PHPMD.NPathComplexity)
70-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
69+
* @SuppressWarnings(PHPMD)
7170
*/
7271
public function resolveOperationDataArray($entityObject, $operationMetadata, $operation, $fromArray = false)
7372
{
@@ -124,7 +123,7 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
124123

125124
$dataReferenceResolver = new RuntimeDataReferenceResolver();
126125
foreach ($operationDataArray as $key => $operationDataValue) {
127-
if (is_array($operationDataValue)){
126+
if (is_array($operationDataValue)) {
128127
continue;
129128
}
130129
$operationDataArray[$key] = $dataReferenceResolver->getDataReference(

src/Magento/FunctionalTestingFramework/DataGenerator/Util/GenerationDataReferenceResolver.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@
1212

1313
class GenerationDataReferenceResolver implements DataReferenceResolverInterface
1414
{
15+
/**
16+
* @param string $data
17+
* @param string $originalDataEntity
18+
* @return string|null
19+
* @throws TestReferenceException
20+
*/
21+
public function getDataUniqueness(string $data, string $originalDataEntity)
22+
{
23+
preg_match(
24+
ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN,
25+
$data,
26+
$matches
27+
);
28+
29+
if (empty($matches['reference'])) {
30+
return null;
31+
}
32+
33+
$strippedReference = str_replace(['{{', '}}'], '', $matches['reference']);
34+
list($entity, $var) = explode('.', $strippedReference);
35+
$entityObject = DataObjectHandler::getInstance()->getObject($entity);
36+
if ($entityObject === null) {
37+
throw new TestReferenceException(
38+
"Could not resolve entity reference \"{$matches['reference']}\" "
39+
. "in Data entity \"{$originalDataEntity}\""
40+
);
41+
}
42+
43+
return $entityObject->getUniquenessDataByName($var);
44+
}
45+
1546
/**
1647
* @param string $data
1748
* @param string $originalDataEntity
@@ -48,35 +79,4 @@ public function getDataReference(string $data, string $originalDataEntity)
4879

4980
return $result;
5081
}
51-
52-
/**
53-
* @param string $data
54-
* @param string $originalDataEntity
55-
* @return string|null
56-
* @throws TestReferenceException
57-
*/
58-
public function getDataUniqueness(string $data, string $originalDataEntity)
59-
{
60-
preg_match(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN,
61-
$data,
62-
$matches
63-
);
64-
65-
if (empty($matches['reference'])) {
66-
return null;
67-
}
68-
69-
$strippedReference = str_replace(['{{', '}}'], '', $matches['reference']);
70-
list($entity, $var) = explode('.', $strippedReference);
71-
$entityObject = DataObjectHandler::getInstance()->getObject($entity);
72-
if ($entityObject === null) {
73-
throw new TestReferenceException(
74-
"Could not resolve entity reference \"{$matches['reference']}\" "
75-
. "in Data entity \"{$originalDataEntity}\""
76-
);
77-
78-
}
79-
80-
return $entityObject->getUniquenessDataByName($var);
81-
}
8282
}

src/Magento/FunctionalTestingFramework/DataGenerator/Util/RuntimeDataReferenceResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public function getDataReference(string $data, string $originalDataEntity)
6363
*/
6464
public function getDataUniqueness(string $data, string $originalDataEntity)
6565
{
66-
preg_match(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN,
66+
preg_match(
67+
ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN,
6768
$data,
6869
$matches
6970
);
@@ -80,7 +81,6 @@ public function getDataUniqueness(string $data, string $originalDataEntity)
8081
"Could not resolve entity reference \"{$matches['reference']}\" "
8182
. "in Data entity \"{$originalDataEntity}\""
8283
);
83-
8484
}
8585

8686
return $entityObject->getUniquenessDataByName($var);

0 commit comments

Comments
 (0)