Skip to content

Commit dd2da2e

Browse files
committed
MQE-1561: CreateData action must be able to parse Data entity which references another data
- Added phpdoc blocks
1 parent 32967a2 commit dd2da2e

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
1111
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1212

13+
/**
14+
* Class resolves data references in data entities while generating static test files.
15+
*/
1316
class GenerationDataReferenceResolver implements DataReferenceResolverInterface
1417
{
1518
/**
19+
* Returns data uniqueness for data entity field.
20+
*
21+
*
1622
* @param string $data
1723
* @param string $originalDataEntity
1824
* @return string|null
@@ -44,6 +50,8 @@ public function getDataUniqueness(string $data, string $originalDataEntity)
4450
}
4551

4652
/**
53+
* Returns data by reference if reference exist.
54+
*
4755
* @param string $data
4856
* @param string $originalDataEntity
4957
* @return string|null
@@ -69,11 +77,17 @@ public function getDataReference(string $data, string $originalDataEntity)
6977
$entityObject = DataObjectHandler::getInstance()->getObject($entity);
7078
if ($entityObject === null) {
7179
throw new TestReferenceException(
72-
"Could not resolve entity reference \"{$matches['reference']}\" "
73-
. "in Data entity \"{$originalDataEntity}\""
80+
"Could not find data entity by name \"{$entityObject}\" "
81+
. "referenced in Data entity \"{$originalDataEntity}\"" . PHP_EOL
7482
);
7583
}
7684
$entityData = $entityObject->getAllData();
85+
if (!isset($entityData[$var])) {
86+
throw new TestReferenceException(
87+
"Could not resolve entity reference \"{$matches['reference']}\" "
88+
. "in Data entity \"{$originalDataEntity}\"" . PHP_EOL
89+
);
90+
}
7791
$result = $entityData[$var];
7892
}
7993

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
1212
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1313

14+
/**
15+
* Class resolves data references in data entities at the runtime of tests.
16+
*/
1417
class RuntimeDataReferenceResolver implements DataReferenceResolverInterface
1518
{
1619
/**
20+
* Returns data by reference if reference exist.
21+
*
1722
* @param string $data
1823
* @param string $originalDataEntity
1924
* @return array|false|string|null
@@ -44,18 +49,26 @@ public function getDataReference(string $data, string $originalDataEntity)
4449
$entityObject = DataObjectHandler::getInstance()->getObject($entity);
4550
if ($entityObject === null) {
4651
throw new TestReferenceException(
47-
"Could not resolve entity reference \"{$matches['reference']}\" "
48-
. "in Data entity \"{$originalDataEntity}\""
52+
"Could not find data entity by name \"{$entityObject}\" "
53+
. "referenced in Data entity \"{$originalDataEntity}\"" . PHP_EOL
4954
);
5055
}
5156
$entityData = $entityObject->getAllData();
57+
if (!isset($entityData[$var])) {
58+
throw new TestReferenceException(
59+
"Could not resolve entity reference \"{$matches['reference']}\" "
60+
. "in Data entity \"{$originalDataEntity}\"" . PHP_EOL
61+
);
62+
}
5263
$result = $entityData[$var];
5364
}
5465

5566
return $result;
5667
}
5768

5869
/**
70+
* Returns data uniqueness for data entity field.
71+
*
5972
* @param string $data
6073
* @param string $originalDataEntity
6174
* @return string|null

0 commit comments

Comments
 (0)