9
9
use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
10
10
use InvalidArgumentException ;
11
11
use Exception ;
12
+ use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
12
13
use Magento \FunctionalTestingFramework \Exceptions \XmlException ;
13
14
use Magento \FunctionalTestingFramework \Page \Objects \SectionObject ;
14
15
use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
@@ -68,6 +69,41 @@ class DeprecatedEntityUsageCheck implements StaticCheckInterface
68
69
*/
69
70
private $ dataOperations = ['create ' , 'update ' , 'get ' , 'delete ' ];
70
71
72
+ /**
73
+ * Test xml files to scan
74
+ *
75
+ * @var Finder|array
76
+ */
77
+ private $ testXmlFiles = [];
78
+
79
+ /**
80
+ * Action group xml files to scan
81
+ *
82
+ * @var Finder|array
83
+ */
84
+ private $ actionGroupXmlFiles = [];
85
+
86
+ /**
87
+ * Suite xml files to scan
88
+ *
89
+ * @var Finder|array
90
+ */
91
+ private $ suiteXmlFiles = [];
92
+
93
+ /**
94
+ * Root suite xml files to scan
95
+ *
96
+ * @var Finder|array
97
+ */
98
+ private $ rootSuiteXmlFiles = [];
99
+
100
+ /**
101
+ * Data xml files to scan
102
+ *
103
+ * @var Finder|array
104
+ */
105
+ private $ dataXmlFiles = [];
106
+
71
107
/**
72
108
* Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module
73
109
*
@@ -78,45 +114,16 @@ class DeprecatedEntityUsageCheck implements StaticCheckInterface
78
114
public function execute (InputInterface $ input )
79
115
{
80
116
$ this ->scriptUtil = new ScriptUtil ();
81
-
82
- $ modulePaths = [];
83
- $ includeRootPath = true ;
84
- $ path = $ input ->getOption ('path ' );
85
- if ($ path ) {
86
- if (!realpath ($ path )) {
87
- throw new InvalidArgumentException ("Invalid --path option: " . $ path );
88
- }
89
- MftfApplicationConfig::create (
90
- true ,
91
- MftfApplicationConfig::UNIT_TEST_PHASE ,
92
- false ,
93
- MftfApplicationConfig::LEVEL_DEFAULT ,
94
- true
95
- );
96
- putenv ('CUSTOM_MODULE_PATHS= ' . realpath ($ path ));
97
- $ modulePaths [] = realpath ($ path );
98
- $ includeRootPath = false ;
99
- } else {
100
- $ modulePaths = $ this ->scriptUtil ->getAllModulePaths ();
101
- }
102
-
103
- // These files can contain references to other entities
104
- $ testXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'Test ' );
105
- $ actionGroupXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'ActionGroup ' );
106
- $ suiteXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'Suite ' );
107
- if ($ includeRootPath ) {
108
- $ rootSuiteXmlFiles = $ this ->scriptUtil ->getRootSuiteXmlFiles ();
109
- }
110
- $ dataXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'Data ' );
117
+ $ this ->loadAllXmlFiles ($ input );
111
118
112
119
$ this ->errors = [];
113
- $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ testXmlFiles );
114
- $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ actionGroupXmlFiles );
115
- $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ suiteXmlFiles , true );
116
- if ($ includeRootPath && !empty ($ rootSuiteXmlFiles )) {
117
- $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ rootSuiteXmlFiles , true );
120
+ $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ this -> testXmlFiles );
121
+ $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ this -> actionGroupXmlFiles );
122
+ $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ this -> suiteXmlFiles , true );
123
+ if (!empty ($ this -> rootSuiteXmlFiles )) {
124
+ $ this ->errors += $ this ->findReferenceErrorsInActionFiles ($ this -> rootSuiteXmlFiles , true );
118
125
}
119
- $ this ->errors += $ this ->findReferenceErrorsInDataFiles ($ dataXmlFiles );
126
+ $ this ->errors += $ this ->findReferenceErrorsInDataFiles ($ this -> dataXmlFiles );
120
127
121
128
// Hold on to the output and print any errors to a file
122
129
$ this ->output = $ this ->scriptUtil ->printErrorsToFile (
@@ -146,6 +153,63 @@ public function getOutput()
146
153
return $ this ->output ;
147
154
}
148
155
156
+ /**
157
+ * Read all XML files for scanning
158
+ *
159
+ * @param InputInterface $input
160
+ * @throws Exception
161
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
162
+ */
163
+ private function loadAllXmlFiles ($ input )
164
+ {
165
+ $ modulePaths = [];
166
+ $ includeRootPath = true ;
167
+ $ path = $ input ->getOption ('path ' );
168
+ if ($ path ) {
169
+ if (!realpath ($ path )) {
170
+ throw new InvalidArgumentException ('Invalid --path option: ' . $ path );
171
+ }
172
+ MftfApplicationConfig::create (
173
+ true ,
174
+ MftfApplicationConfig::UNIT_TEST_PHASE ,
175
+ false ,
176
+ MftfApplicationConfig::LEVEL_DEFAULT ,
177
+ true
178
+ );
179
+ putenv ('CUSTOM_MODULE_PATHS= ' . realpath ($ path ));
180
+ $ modulePaths [] = realpath ($ path );
181
+ $ includeRootPath = false ;
182
+ } else {
183
+ $ modulePaths = $ this ->scriptUtil ->getAllModulePaths ();
184
+ }
185
+
186
+ // These files can contain references to other entities
187
+ $ this ->testXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'Test ' );
188
+ $ this ->actionGroupXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'ActionGroup ' );
189
+ $ this ->suiteXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'Suite ' );
190
+ if ($ includeRootPath ) {
191
+ $ this ->rootSuiteXmlFiles = $ this ->scriptUtil ->getRootSuiteXmlFiles ();
192
+ }
193
+ $ this ->dataXmlFiles = $ this ->scriptUtil ->getModuleXmlFilesByScope ($ modulePaths , 'Data ' );
194
+
195
+ if (empty ($ this ->thistestXmlFiles )
196
+ && empty ($ this ->actionGroupXmlFiles )
197
+ && empty ($ this ->suiteXmlFiles )
198
+ && empty ($ this ->dataXmlFiles )
199
+ ) {
200
+ if ($ path ) {
201
+ throw new InvalidArgumentException (
202
+ 'Invalid --path option: '
203
+ . $ path
204
+ . PHP_EOL
205
+ . 'Please make sure --path points to a valid MFTF Test Module. '
206
+ );
207
+ } elseif (empty ($ this ->rootSuiteXmlFiles )) {
208
+ throw new TestFrameworkException ('No xml file to scan. ' );
209
+ }
210
+ }
211
+ }
212
+
149
213
/**
150
214
* Find reference errors in set of action files
151
215
*
@@ -190,58 +254,39 @@ private function findReferenceErrorsInActionFiles($files, $checkTestRef = false)
190
254
191
255
// Resolve entity references
192
256
$ entityReferences = $ this ->scriptUtil ->resolveEntityReferences ($ braceReferences [0 ], $ contents , true );
193
-
194
257
// Resolve parameterized references
195
258
$ entityReferences = array_merge (
196
259
$ entityReferences ,
197
260
$ this ->scriptUtil ->resolveParametrizedReferences ($ braceReferences [2 ], $ contents , true )
198
261
);
199
-
200
262
// Resolve action group entity by names
201
263
$ entityReferences = array_merge (
202
264
$ entityReferences ,
203
265
$ this ->scriptUtil ->resolveEntityByNames ($ actionGroupReferences [1 ])
204
266
);
205
-
206
267
// Resolve extends entity by names
207
268
$ entityReferences = array_merge (
208
269
$ entityReferences ,
209
270
$ this ->scriptUtil ->resolveEntityByNames ($ extendReferences [1 ])
210
271
);
211
-
212
272
// Resolve create data entity by names
213
273
$ entityReferences = array_merge (
214
274
$ entityReferences ,
215
275
$ this ->scriptUtil ->resolveEntityByNames ($ createdDataReferences )
216
276
);
217
-
218
277
// Resolve update data entity by names
219
278
$ entityReferences = array_merge (
220
279
$ entityReferences ,
221
280
$ this ->scriptUtil ->resolveEntityByNames ($ updatedDataReferences )
222
281
);
223
-
224
282
// Resolve get data entity by names
225
283
$ entityReferences = array_merge (
226
284
$ entityReferences ,
227
285
$ this ->scriptUtil ->resolveEntityByNames ($ getDataReferences )
228
286
);
229
-
230
287
// Find test references if needed
231
288
if ($ checkTestRef ) {
232
- $ testReferences = $ this ->getAttributesFromDOMNodeList (
233
- $ domDocument ->getElementsByTagName ('test ' ),
234
- 'name '
235
- );
236
-
237
- // Remove Duplicates
238
- $ testReferences = array_unique ($ testReferences );
239
-
240
- // Resolve test entity by names
241
- $ entityReferences = array_merge (
242
- $ entityReferences ,
243
- $ this ->scriptUtil ->resolveEntityByNames ($ testReferences )
244
- );
289
+ $ entityReferences = array_merge ($ entityReferences , $ this ->resolveTestEntityInSuite ($ domDocument ));
245
290
}
246
291
247
292
// Find violating references
@@ -602,6 +647,30 @@ private function setErrorOutput($violatingReferences, $path)
602
647
return $ testErrors ;
603
648
}
604
649
650
+ /**
651
+ * Resolve test entity in suite
652
+ *
653
+ * @param \DOMDocument $domDocument
654
+ * @return array
655
+ */
656
+ private function resolveTestEntityInSuite ($ domDocument )
657
+ {
658
+ $ testReferences = $ this ->getAttributesFromDOMNodeList (
659
+ $ domDocument ->getElementsByTagName ('test ' ),
660
+ 'name '
661
+ );
662
+
663
+ // Remove Duplicates
664
+ $ testReferences = array_unique ($ testReferences );
665
+
666
+ // Resolve test entity by names
667
+ try {
668
+ return $ this ->scriptUtil ->resolveEntityByNames ($ testReferences );
669
+ } catch (XmlException $ e ) {
670
+ return [];
671
+ }
672
+ }
673
+
605
674
/**
606
675
* Return subject string for a class name
607
676
*
0 commit comments