diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php index 6c3823466..592b87f4e 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php @@ -32,6 +32,30 @@ public function setUp() TestLoggingUtil::getInstance()->setMockLoggingUtil(); } + public function testCreateEntityWithNonExistingName() + { + // Test Data and Variables + $entityName = "InvalidEntity"; + $entityStepKey = "StepKey"; + $scope = PersistedObjectHandler::TEST_SCOPE; + + $exceptionMessage = "Entity \"" . $entityName . "\" does not exist." . + "\nException occurred executing action at StepKey \"" . $entityStepKey . "\""; + + $this->expectException(TestReferenceException::class); + + $this->expectExceptionMessage($exceptionMessage); + + $handler = PersistedObjectHandler::getInstance(); + + // Call method + $handler->createEntity( + $entityStepKey, + $scope, + $entityName + ); + } + public function testCreateSimpleEntity() { // Test Data and Variables diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php index 2a0f11a01..00353856b 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php @@ -97,6 +97,14 @@ public function createEntity( } $retrievedEntity = DataObjectHandler::getInstance()->getObject($entity); + + if ($retrievedEntity === null) { + throw new TestReferenceException( + "Entity \"" . $entity . "\" does not exist." . + "\nException occurred executing action at StepKey \"" . $key . "\"" + ); + } + $persistedObject = new DataPersistenceHandler( $retrievedEntity, $retrievedDependentObjects,