Skip to content

Commit 4e1ea0a

Browse files
committed
MQE-1513: createData throws a useless error message during runtime when the entity does not exist
1 parent 9bc59f8 commit 4e1ea0a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1515
use Magento\FunctionalTestingFramework\Util\TestGenerator;
1616
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
17+
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
1718

1819
class TestGeneratorTest extends MagentoTestCase
1920
{
@@ -41,11 +42,36 @@ public function testEntityException()
4142
$testGeneratorObject->createAllTestFiles(null, []);
4243
}
4344

45+
/**
46+
* Test to check exceptions for createData on referencing non-existent entity
47+
*
48+
* @throws TestReferenceException
49+
*/
50+
51+
public function testCreateDataException()
52+
{
53+
$actionObject = new ActionObject('fakeAction', 'createData', [
54+
'entity' => 'invalidEntity'
55+
]);
56+
57+
$testObject = new TestObject("sampleTest", ["merge123" => $actionObject], [], [], "filename");
58+
59+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $testObject]);
60+
61+
AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $testObject]]);
62+
63+
$this->expectExceptionMessage("Entity \"invalidEntity\" does not exist." .
64+
"\nException occurred parsing action at StepKey \"fakeAction\" in Test \"sampleTest\"");
65+
66+
$testGeneratorObject->createAllTestFiles(null, []);
67+
}
68+
4469
/**
4570
* Tests that skipped tests do not have a fully generated body
4671
*
4772
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
4873
*/
74+
4975
public function testSkippedNoGeneration()
5076
{
5177
$actionInput = 'fakeInput';

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,13 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
731731
case "createData":
732732
$entity = $customActionAttributes['entity'];
733733

734+
if(DataObjectHandler::getInstance()->getObject($entity) === null) {
735+
throw new TestReferenceException(
736+
"Entity \"" . $entity . "\" does not exist." .
737+
"\nException occurred parsing action at StepKey \"" . $stepKey . "\""
738+
);
739+
}
740+
734741
//TODO refactor entity field override to not be individual actionObjects
735742
$customEntityFields =
736743
$customActionAttributes[ActionObjectExtractor::ACTION_OBJECT_PERSISTENCE_FIELDS] ?? [];

0 commit comments

Comments
 (0)