6
6
7
7
namespace Magento \FunctionalTestingFramework \Util ;
8
8
9
+ use FilesystemIterator ;
9
10
use Magento \FunctionalTestingFramework \DataGenerator \Objects \EntityDataObject ;
10
11
use Magento \FunctionalTestingFramework \Test \Handlers \CestObjectHandler ;
11
12
use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
12
13
use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
14
+ use Magento \FunctionalTestingFramework \Test \Objects \CestObject ;
15
+ use RecursiveDirectoryIterator ;
13
16
14
17
class TestGenerator
15
18
{
19
+
20
+ /**
21
+ * Path to the export dir.
22
+ *
23
+ * @var string
24
+ */
25
+ private $ exportDirectory ;
26
+
16
27
/**
17
28
* Test generator.
18
29
*
@@ -23,9 +34,47 @@ class TestGenerator
23
34
/**
24
35
* TestGenerator constructor.
25
36
*/
26
- private function __construct ()
37
+ private function __construct ($ exportDir )
27
38
{
28
39
// 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 );
29
78
}
30
79
31
80
/**
@@ -36,7 +85,7 @@ private function __construct()
36
85
public static function getInstance ()
37
86
{
38
87
if (!self ::$ testGenerator ) {
39
- self ::$ testGenerator = new TestGenerator ();
88
+ self ::$ testGenerator = new TestGenerator (TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . " _generated " );
40
89
}
41
90
42
91
return self ::$ testGenerator ;
@@ -63,13 +112,7 @@ private function loadAllCestObjects()
63
112
*/
64
113
private function createCestFile ($ cestPhp , $ filename )
65
114
{
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 " ;
73
116
$ file = fopen ($ exportFilePath , 'w ' );
74
117
75
118
if (!$ file ) {
@@ -88,6 +131,7 @@ private function createCestFile($cestPhp, $filename)
88
131
*/
89
132
public function createAllCestFiles ()
90
133
{
134
+ $ this ->setupExportDir ();
91
135
$ cestPhpArray = $ this ->assembleAllCestPhp ();
92
136
93
137
foreach ($ cestPhpArray as $ cestPhpFile ) {
@@ -134,11 +178,17 @@ private function assembleAllCestPhp()
134
178
$ cestObjects = $ this ->loadAllCestObjects ();
135
179
$ cestPhpArray = [];
136
180
181
+ // create our manifest file here
182
+ $ testManifest = new TestManifest ($ this ->exportDirectory );
183
+
137
184
foreach ($ cestObjects as $ cest ) {
138
185
$ name = $ cest ->getName ();
139
186
$ name = $ string = str_replace (' ' , '' , $ name );
140
187
$ php = $ this ->assembleCestPhp ($ cest );
141
188
$ cestPhpArray [] = [$ name , $ php ];
189
+
190
+ //write to manifest here
191
+ $ testManifest ->recordCest ($ cest ->getName (), $ cest ->getTests ());
142
192
}
143
193
144
194
return $ cestPhpArray ;
0 commit comments