66
77namespace Magento \FunctionalTestingFramework \Util ;
88
9+ use FilesystemIterator ;
910use Magento \FunctionalTestingFramework \DataGenerator \Objects \EntityDataObject ;
1011use Magento \FunctionalTestingFramework \Test \Handlers \CestObjectHandler ;
1112use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
1213use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
14+ use Magento \FunctionalTestingFramework \Test \Objects \CestObject ;
15+ use RecursiveDirectoryIterator ;
1316
1417class TestGenerator
1518{
19+
20+ /**
21+ * Path to the export dir.
22+ *
23+ * @var string
24+ */
25+ private $ exportDirectory ;
26+
1627 /**
1728 * Test generator.
1829 *
@@ -23,9 +34,47 @@ class TestGenerator
2334 /**
2435 * TestGenerator constructor.
2536 */
26- private function __construct ()
37+ private function __construct ($ exportDir )
2738 {
2839 // private constructor for singleton
40+ $ this ->exportDirectory = $ exportDir ;
41+ }
42+
43+ /**
44+ * Method used to clean export dir if needed and create new empty export dir.
45+ *
46+ * @return void
47+ */
48+ private function setupExportDir ()
49+ {
50+ if (file_exists ($ this ->exportDirectory )) {
51+ $ this ->rmDirRecursive ($ this ->exportDirectory );
52+ }
53+
54+ mkdir ($ this ->exportDirectory , 0777 , true );
55+ }
56+
57+ /**
58+ * Takes a directory path and recursively deletes all files and folders.
59+ *
60+ * @param string $directory
61+ */
62+ private function rmdirRecursive ($ directory )
63+ {
64+ $ it = new RecursiveDirectoryIterator ($ directory , FilesystemIterator::SKIP_DOTS );
65+
66+ while ($ it ->valid ()) {
67+ $ path = $ directory . DIRECTORY_SEPARATOR . $ it ->getFilename ();
68+ if ($ it ->isDir ()) {
69+ $ this ->rmDirRecursive ($ path );
70+ } else {
71+ unlink ($ path );
72+ }
73+
74+ $ it ->next ();
75+ }
76+
77+ rmdir ($ directory );
2978 }
3079
3180 /**
@@ -36,7 +85,7 @@ private function __construct()
3685 public static function getInstance ()
3786 {
3887 if (!self ::$ testGenerator ) {
39- self ::$ testGenerator = new TestGenerator ();
88+ self ::$ testGenerator = new TestGenerator (TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . " _generated " );
4089 }
4190
4291 return self ::$ testGenerator ;
@@ -63,13 +112,7 @@ private function loadAllCestObjects()
63112 */
64113 private function createCestFile ($ cestPhp , $ filename )
65114 {
66- $ exportDirectory = TESTS_MODULE_PATH . "/_generated " ;
67- $ exportFilePath = sprintf ("%s/%s.php " , $ exportDirectory , $ filename );
68-
69- if (!is_dir ($ exportDirectory )) {
70- mkdir ($ exportDirectory , 0777 , true );
71- }
72-
115+ $ exportFilePath = $ this ->exportDirectory . DIRECTORY_SEPARATOR . $ filename . ".php " ;
73116 $ file = fopen ($ exportFilePath , 'w ' );
74117
75118 if (!$ file ) {
@@ -88,6 +131,7 @@ private function createCestFile($cestPhp, $filename)
88131 */
89132 public function createAllCestFiles ()
90133 {
134+ $ this ->setupExportDir ();
91135 $ cestPhpArray = $ this ->assembleAllCestPhp ();
92136
93137 foreach ($ cestPhpArray as $ cestPhpFile ) {
@@ -134,11 +178,17 @@ private function assembleAllCestPhp()
134178 $ cestObjects = $ this ->loadAllCestObjects ();
135179 $ cestPhpArray = [];
136180
181+ // create our manifest file here
182+ $ testManifest = new TestManifest ($ this ->exportDirectory );
183+
137184 foreach ($ cestObjects as $ cest ) {
138185 $ name = $ cest ->getName ();
139186 $ name = $ string = str_replace (' ' , '' , $ name );
140187 $ php = $ this ->assembleCestPhp ($ cest );
141188 $ cestPhpArray [] = [$ name , $ php ];
189+
190+ //write to manifest here
191+ $ testManifest ->recordCest ($ cest ->getName (), $ cest ->getTests ());
142192 }
143193
144194 return $ cestPhpArray ;
0 commit comments