Skip to content

Commit 669ca53

Browse files
committed
Add possibility to include multiple non primitive types in an array
If an array is defined for an entity it is currently not possible to include different types of non primitive types in the same array.
1 parent 3c7ed4b commit 669ca53

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
109109
$operationElementType,
110110
$operationDataArray
111111
);
112+
} else if (is_array($operationElementType)) {
113+
foreach ($operationElementType as $currentElementType) {
114+
if (in_array($currentElementType, self::PRIMITIVE_TYPES)) {
115+
$this->resolvePrimitiveReferenceElement(
116+
$entityObject,
117+
$operationElement,
118+
$currentElementType,
119+
$operationDataArray
120+
);
121+
} else {
122+
$this->resolveNonPrimitiveReferenceElement(
123+
$entityObject,
124+
$operation,
125+
$fromArray,
126+
$currentElementType,
127+
$operationElement,
128+
$operationDataArray
129+
);
130+
}
131+
}
112132
} else {
113133
$this->resolveNonPrimitiveReferenceElement(
114134
$entityObject,
@@ -236,7 +256,7 @@ private function resolveNonPrimitiveElement($entityName, $operationElement, $ope
236256
$linkedEntityObj = $this->resolveLinkedEntityObject($entityName);
237257

238258
// in array case
239-
if (!empty($operationElement->getNestedOperationElement($operationElement->getValue()))
259+
if (!is_array($operationElement->getValue()) && !empty($operationElement->getNestedOperationElement($operationElement->getValue()))
240260
&& $operationElement->getType() == OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY
241261
) {
242262
$operationSubArray = $this->resolveOperationDataArray(

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,16 @@ private function extractOperationField(&$operationElements, $operationFieldArray
112112
private function extractOperationArray(&$operationArrayData, $operationArrayArray)
113113
{
114114
foreach ($operationArrayArray as $operationFieldType) {
115-
$operationElementValue =
116-
$operationFieldType[OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY_VALUE][0]
117-
[OperationElementExtractor::OPERATION_OBJECT_ARRAY_VALUE] ?? null;
115+
$operationElementValue = [];
116+
if (isset($operationFieldType[OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY_VALUE])) {
117+
foreach ($operationFieldType[OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY_VALUE] as $operationFieldValue) {
118+
$operationElementValue[] = $operationFieldValue[OperationElementExtractor::OPERATION_OBJECT_ARRAY_VALUE] ?? null;
119+
}
120+
}
121+
122+
if (count($operationElementValue) === 1) {
123+
$operationElementValue = array_pop($operationElementValue);
124+
}
118125

119126
$nestedOperationElements = [];
120127
if (array_key_exists(OperationElementExtractor::OPERATION_OBJECT_OBJ_NAME, $operationFieldType)) {

0 commit comments

Comments
 (0)