@@ -139,10 +139,6 @@ public function beforeExample(ExampleEvent $event): void
139
139
$ this ->coverage ->start ($ name );
140
140
}
141
141
142
- /**
143
- * Note: We use array_map() instead of array_walk() because the latter expects
144
- * the callback to take the value as the first and the index as the seconds parameter.
145
- */
146
142
public function beforeSuite (SuiteEvent $ event ): void
147
143
{
148
144
if ($ this ->skipCoverage ) {
@@ -151,26 +147,36 @@ public function beforeSuite(SuiteEvent $event): void
151
147
152
148
$ filter = $ this ->coverage ->filter ();
153
149
154
- foreach ($ this ->options ['whitelist ' ] as $ option ) {
150
+ //We compute the list of file / folder to be excluded
151
+ //If the blacklist contains suffixes and/or prefixes, we extract an
152
+ //exhaustive list of files that match to be added in the excluded list.
153
+ $ excludes = $ this ->options ['blacklist_files ' ];
154
+ foreach ($ this ->options ['blacklist ' ] as $ option ) {
155
155
$ settings = $ this ->filterDirectoryParams ($ option );
156
-
157
- foreach ((new FileIteratorFacade ())->getFilesAsArray ($ settings ['directory ' ], $ settings ['suffix ' ], $ settings ['prefix ' ]) as $ file ) {
158
- $ filter ->includeFile ($ file );
156
+ if (!empty ($ settings ['suffix ' ]) || !empty ($ settings ['prefix ' ])) {
157
+ $ excludes = $ excludes + (new FileIteratorFacade ())->getFilesAsArray (
158
+ $ settings ['directory ' ],
159
+ $ settings ['suffix ' ],
160
+ $ settings ['prefix ' ]
161
+ );
162
+ } else {
163
+ $ excludes [] = $ settings ['directory ' ];
159
164
}
160
165
}
161
166
162
- foreach ($ this ->options ['blacklist ' ] as $ option ) {
167
+ foreach ($ this ->options ['whitelist ' ] as $ option ) {
163
168
$ settings = $ this ->filterDirectoryParams ($ option );
164
- foreach ((new FileIteratorFacade )->getFilesAsArray ($ directory , $ suffix , $ prefix ) as $ file ) {
165
- $ filter ->excludeFile ($ file );
169
+ $ fileIterator = (new FileIteratorFacade ())->getFilesAsArray (
170
+ [$ settings ['directory ' ]] + $ this ->options ['whitelist_files ' ],
171
+ $ settings ['suffix ' ],
172
+ $ settings ['prefix ' ],
173
+ //We exclude the files from the previously built list.
174
+ $ excludes
175
+ );
176
+
177
+ foreach ($ fileIterator as $ file ) {
178
+ $ filter ->includeFile ($ file );
166
179
}
167
- $ filter ->excludeDirectory ($ settings ['directory ' ], $ settings ['suffix ' ], $ settings ['prefix ' ]);
168
- }
169
-
170
- $ filter ->includeFiles ($ this ->options ['whitelist_files ' ]);
171
-
172
- foreach ($ this ->options ['blacklist_files ' ] as $ option ) {
173
- $ filter ->excludeFile ($ option );
174
180
}
175
181
}
176
182
@@ -198,7 +204,7 @@ public function setOptions(array $options): void
198
204
/**
199
205
* @param array<string, string>|string $option
200
206
*
201
- * @return array{directory:string, prefix:string, suffix:string}
207
+ * @return array{directory:non-empty- string, prefix:string, suffix:string}
202
208
*/
203
209
protected function filterDirectoryParams ($ option ): array
204
210
{
@@ -213,7 +219,7 @@ protected function filterDirectoryParams($option): array
213
219
));
214
220
}
215
221
216
- if (! isset ($ option ['directory ' ])) {
222
+ if (empty ($ option ['directory ' ])) {
217
223
throw new ConfigurationException ('Missing required directory path. ' );
218
224
}
219
225
0 commit comments