31
31
use Magento \FunctionalTestingFramework \Util \Path \FilePathFormatter ;
32
32
use Mustache_Engine ;
33
33
use Mustache_Loader_FilesystemLoader ;
34
+ use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
34
35
35
36
/**
36
37
* Class TestGenerator
@@ -904,7 +905,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
904
905
break ;
905
906
case "createData " :
906
907
$ entity = $ customActionAttributes ['entity ' ];
907
-
908
+ $ this -> entityExistsCheck ( $ entity , $ stepKey );
908
909
//TODO refactor entity field override to not be individual actionObjects
909
910
$ customEntityFields =
910
911
$ customActionAttributes [ActionObjectExtractor::ACTION_OBJECT_PERSISTENCE_FIELDS ] ?? [];
@@ -922,7 +923,6 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
922
923
if (!empty ($ requiredEntityKeys )) {
923
924
$ requiredEntityKeysArray = '" ' . implode ('", " ' , $ requiredEntityKeys ) . '" ' ;
924
925
}
925
-
926
926
$ scope = $ this ->getObjectScope ($ generationScope );
927
927
928
928
$ createEntityFunctionCall = "\t\t\${$ actor }->createEntity( " ;
@@ -1511,7 +1511,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
1511
1511
}
1512
1512
$ testSteps .= PHP_EOL ;
1513
1513
}
1514
-
1514
+
1515
+
1515
1516
return $ testSteps ;
1516
1517
}
1517
1518
@@ -1673,6 +1674,9 @@ private function resolveStepKeyReferences($input, $actionGroupOrigin, $matchAll
1673
1674
$ testInvocationKey = ucfirst ($ actionGroupOrigin [ActionGroupObject::ACTION_GROUP_ORIGIN_TEST_REF ]);
1674
1675
1675
1676
foreach ($ stepKeys as $ stepKey ) {
1677
+
1678
+
1679
+
1676
1680
// MQE-1011
1677
1681
$ stepKeyVarRef = "$ " . $ stepKey ;
1678
1682
@@ -1877,7 +1881,6 @@ private function generateTestPhp($test)
1877
1881
$ testPhp .= "\t\t\$this->isSuccess = true; " . PHP_EOL ;
1878
1882
$ testPhp .= "\t} \n" ;
1879
1883
}
1880
-
1881
1884
return $ testPhp ;
1882
1885
}
1883
1886
@@ -2049,6 +2052,23 @@ private function addDollarSign($input)
2049
2052
return sprintf ("$%s " , ltrim ($ this ->stripQuotes ($ input ), '$ ' ));
2050
2053
}
2051
2054
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
+
2052
2072
/**
2053
2073
* Wrap parameters into a function call.
2054
2074
*
0 commit comments