@@ -31,6 +31,18 @@ class Files
31
31
*/
32
32
protected $ _path = '' ;
33
33
34
+ /** @var string regex for test directories in app/code */
35
+ protected $ moduleTestDirs = '#app/code/[ \\w]+/[ \\w]+/Test# ' ;
36
+
37
+ /** @var string regex for test directories in tools */
38
+ protected $ toolsTestDirs = '#dev/tools/Magento/Tools/[ \\w]+/Test# ' ;
39
+
40
+ /** @var string regex for test directories in framework */
41
+ protected $ frameworkTestDirs = '#lib/internal/Magento/Framework/[ \\w]+/Test# ' ;
42
+
43
+ /** @var string regex for test directories in lib/internal */
44
+ protected $ libTestDirs = '#lib/internal/[ \\w]+/[ \\w]+/Test# ' ;
45
+
34
46
/**
35
47
* Setter for an instance of self
36
48
*
@@ -112,15 +124,20 @@ public function getPhpFiles($appCode = true, $otherCode = true, $templates = tru
112
124
if ($ appCode ) {
113
125
$ files = array_merge (
114
126
glob ($ this ->_path . '/app/*.php ' , GLOB_NOSORT ),
115
- self ::getFiles (["{$ this ->_path }/app/code/ {$ namespace }/ {$ module }" ], '*.php ' )
127
+ $ this ->getFilesSubset (
128
+ ["{$ this ->_path }/app/code/ {$ namespace }/ {$ module }" ],
129
+ '*.php ' ,
130
+ $ this ->moduleTestDirs
131
+ )
116
132
);
117
133
}
118
134
if ($ otherCode ) {
135
+ $ exclude = [$ this ->libTestDirs , $ this ->frameworkTestDirs ];
119
136
$ files = array_merge (
120
137
$ files ,
121
138
glob ($ this ->_path . '/*.php ' , GLOB_NOSORT ),
122
139
glob ($ this ->_path . '/pub/*.php ' , GLOB_NOSORT ),
123
- self :: getFiles (["{$ this ->_path }/lib/internal/Magento " ], '*.php ' ),
140
+ $ this -> getFilesSubset (["{$ this ->_path }/lib/internal/Magento " ], '*.php ' , $ exclude ),
124
141
self ::getFiles (["{$ this ->_path }/dev/tools/Magento/Tools/SampleData " ], '*.php ' )
125
142
);
126
143
}
@@ -140,49 +157,52 @@ public function getPhpFiles($appCode = true, $otherCode = true, $templates = tru
140
157
* Returns list of files, where expected to have class declarations
141
158
*
142
159
* @param bool $appCode application PHP-code
143
- * @param bool $devTests
160
+ * @param bool $tests
144
161
* @param bool $devTools
145
162
* @param bool $lib
146
163
* @param bool $asDataSet
147
164
* @return array
148
165
*/
149
166
public function getClassFiles (
150
167
$ appCode = true ,
151
- $ devTests = true ,
168
+ $ tests = true ,
152
169
$ devTools = true ,
153
170
$ lib = true ,
154
171
$ asDataSet = true
155
172
) {
156
- $ key = __METHOD__ . "/ {$ this ->_path }/ {$ appCode }/ {$ devTests }/ {$ devTools }/ {$ lib }" ;
173
+ $ key = __METHOD__ . "/ {$ this ->_path }/ {$ appCode }/ {$ tests }/ {$ devTools }/ {$ lib }" ;
157
174
if (!isset (self ::$ _cache [$ key ])) {
158
175
$ files = [];
159
176
if ($ appCode ) {
160
- $ appFiles = self ::getFiles (["{$ this ->_path }/app/code/Magento " ], '*.php ' );
161
- $ appFiles = preg_grep ('#app/code/[ \\w]+/[ \\w]+/Test# ' , $ appFiles , PREG_GREP_INVERT );
162
- $ files = array_merge ($ files , $ appFiles );
177
+ $ files = array_merge (
178
+ $ files ,
179
+ $ this ->getFilesSubset (["{$ this ->_path }/app/code/Magento " ], '*.php ' , $ this ->moduleTestDirs )
180
+ );
163
181
}
164
- if ($ devTests ) {
182
+ if ($ tests ) {
165
183
$ testDirs = [
166
184
"{$ this ->_path }/dev/tests " ,
167
185
"{$ this ->_path }/app/code/*/*/Test " ,
168
186
"{$ this ->_path }/lib/internal/*/*/Test " ,
169
187
"{$ this ->_path }/lib/internal/Magento/Framework/*/Test " ,
170
188
"{$ this ->_path }/dev/tools/Magento/Tools/*/Test " ,
171
- "{$ this ->_path }/setup/Test " ,
189
+ "{$ this ->_path }/setup/src/Magento/Setup/ Test " ,
172
190
173
191
];
174
192
$ files = array_merge ($ files , self ::getFiles ($ testDirs , '*.php ' ));
175
193
}
176
194
if ($ devTools ) {
177
- $ toolFiles = self ::getFiles (["{$ this ->_path }/dev/tools/Magento " ], '*.php ' );
178
- $ toolFiles = preg_grep ('#dev/tools/Magento/Tools/[ \\w]+/Test# ' , $ toolFiles , PREG_GREP_INVERT );
179
- $ files = array_merge ($ files , $ toolFiles );
195
+ $ files = array_merge (
196
+ $ files ,
197
+ $ this ->getFilesSubset (["{$ this ->_path }/dev/tools/Magento " ], '*.php ' , $ this ->toolsTestDirs )
198
+ );
180
199
}
181
200
if ($ lib ) {
182
- $ libFiles = self ::getFiles (["{$ this ->_path }/lib/internal/Magento " ], '*.php ' );
183
- $ libFiles = preg_grep ('#lib/internal/Magento/Framework/[ \\w]+/Test# ' , $ libFiles , PREG_GREP_INVERT );
184
- $ libFiles = preg_grep ('#lib/internal/[ \\w]+/[ \\w]+/Test# ' , $ libFiles , PREG_GREP_INVERT );
185
- $ files = array_merge ($ files , $ libFiles );
201
+ $ exclude = [$ this ->libTestDirs , $ this ->frameworkTestDirs ];
202
+ $ files = array_merge (
203
+ $ files ,
204
+ $ this ->getFilesSubset (["{$ this ->_path }/lib/internal/Magento " ], '*.php ' , $ exclude )
205
+ );
186
206
}
187
207
self ::$ _cache [$ key ] = $ files ;
188
208
}
@@ -1049,7 +1069,7 @@ public function getComposerFiles($appDir, $asDataSet = true)
1049
1069
{
1050
1070
$ key = __METHOD__ . '| ' . $ this ->_path . '| ' . serialize (func_get_args ());
1051
1071
if (!isset (self ::$ _cache [$ key ])) {
1052
- $ files = self :: getFiles (["{$ this ->_path }/app/ {$ appDir }" ], 'composer.json ' );
1072
+ $ files = $ this -> getFilesSubset (["{$ this ->_path }/app/ {$ appDir }" ], 'composer.json ' , $ this -> moduleTestDirs );
1053
1073
self ::$ _cache [$ key ] = $ files ;
1054
1074
}
1055
1075
@@ -1111,4 +1131,24 @@ public function isModuleExists($moduleName)
1111
1131
1112
1132
return self ::$ _cache [$ key ];
1113
1133
}
1134
+
1135
+ /**
1136
+ * Returns list of files in a given directory, minus files in specifically excluded directories.
1137
+ *
1138
+ * @param array $dirPatterns Directories to search in
1139
+ * @param string $fileNamePattern Pattern for filename
1140
+ * @param string|array $excludes Subdirectories to exlude, represented as regex
1141
+ * @return array Files in $dirPatterns but not in $excludes
1142
+ */
1143
+ protected function getFilesSubset (array $ dirPatterns , $ fileNamePattern , $ excludes )
1144
+ {
1145
+ if (!is_array ($ excludes )) {
1146
+ $ excludes = [$ excludes ];
1147
+ }
1148
+ $ fileSet = self ::getFiles ($ dirPatterns , $ fileNamePattern );
1149
+ foreach ($ excludes as $ excludeRegex ) {
1150
+ $ fileSet = preg_grep ($ excludeRegex , $ fileSet , PREG_GREP_INVERT );
1151
+ }
1152
+ return $ fileSet ;
1153
+ }
1114
1154
}
0 commit comments