3131use Magento \FunctionalTestingFramework \Util \Path \FilePathFormatter ;
3232use Mustache_Engine ;
3333use Mustache_Loader_FilesystemLoader ;
34+ use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
3435
3536/**
3637 * Class TestGenerator
@@ -904,7 +905,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
904905 break ;
905906 case "createData " :
906907 $ entity = $ customActionAttributes ['entity ' ];
907-
908+ $ this -> entityExistsCheck ( $ entity , $ stepKey );
908909 //TODO refactor entity field override to not be individual actionObjects
909910 $ customEntityFields =
910911 $ customActionAttributes [ActionObjectExtractor::ACTION_OBJECT_PERSISTENCE_FIELDS ] ?? [];
@@ -922,7 +923,6 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
922923 if (!empty ($ requiredEntityKeys )) {
923924 $ requiredEntityKeysArray = '" ' . implode ('", " ' , $ requiredEntityKeys ) . '" ' ;
924925 }
925-
926926 $ scope = $ this ->getObjectScope ($ generationScope );
927927
928928 $ createEntityFunctionCall = "\t\t\${$ actor }->createEntity( " ;
@@ -1511,7 +1511,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
15111511 }
15121512 $ testSteps .= PHP_EOL ;
15131513 }
1514-
1514+
1515+
15151516 return $ testSteps ;
15161517 }
15171518
@@ -1673,6 +1674,9 @@ private function resolveStepKeyReferences($input, $actionGroupOrigin, $matchAll
16731674 $ testInvocationKey = ucfirst ($ actionGroupOrigin [ActionGroupObject::ACTION_GROUP_ORIGIN_TEST_REF ]);
16741675
16751676 foreach ($ stepKeys as $ stepKey ) {
1677+
1678+
1679+
16761680 // MQE-1011
16771681 $ stepKeyVarRef = "$ " . $ stepKey ;
16781682
@@ -1877,7 +1881,6 @@ private function generateTestPhp($test)
18771881 $ testPhp .= "\t\t\$this->isSuccess = true; " . PHP_EOL ;
18781882 $ testPhp .= "\t} \n" ;
18791883 }
1880-
18811884 return $ testPhp ;
18821885 }
18831886
@@ -2049,6 +2052,23 @@ private function addDollarSign($input)
20492052 return sprintf ("$%s " , ltrim ($ this ->stripQuotes ($ input ), '$ ' ));
20502053 }
20512054
2055+ /**
2056+ * Check if the entity exists
2057+ *
2058+ * @param string $entity
2059+ * @param string $stepKey
2060+ * @throws TestReferenceException
2061+ */
2062+ public function entityExistsCheck ($ entity , $ stepKey )
2063+ {
2064+ $ retrievedEntity = DataObjectHandler::getInstance ()->getObject ($ entity );
2065+ if ($ retrievedEntity === null ) {
2066+ throw new TestReferenceException (
2067+ "Test generation failed as entity \"" . $ entity . "\" does not exist. at stepkey " .$ stepKey
2068+ );
2069+ }
2070+ }
2071+
20522072 /**
20532073 * Wrap parameters into a function call.
20542074 *
0 commit comments