Skip to content

Commit 175d840

Browse files
committed
deprecation: blacklist and blacklist_files are now deprecated.
Since the phpunit/php-code-coverage isn't able to exclude any folder from version 11, we must check that we are still able to work with blacklist. A specfic error message has been added to explain how to continue using blacklist parameters to users. Also the default blacklist option value was changed, it's now an empty array.
1 parent 61b4936 commit 175d840

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

spec/Listener/CodeCoverageListenerSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function let(ConsoleIO $io, Driver $driver)
3535
public function it_can_process_all_directory_filtering_options(SuiteEvent $event)
3636
{
3737
$this->setOptions([
38-
'blacklist' => [
38+
'whitelist' => [
3939
'src',
4040
['directory' => 'src', 'suffix' => 'Spec.php', 'prefix' => 'Get'],
4141
['directory' => 'src', 'suffix' => 'Test.php'],

src/Listener/CodeCoverageListener.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
6969
$this->reports = $reports;
7070
$this->options = [
7171
'whitelist' => ['src', 'lib'],
72-
'blacklist' => ['test', 'vendor', 'spec'],
72+
'blacklist' => [],
7373
'whitelist_files' => [],
7474
'blacklist_files' => [],
7575
'output' => ['html' => 'coverage'],
@@ -159,16 +159,31 @@ public function beforeSuite(SuiteEvent $event): void
159159
}
160160
}
161161

162+
$filter->includeFiles($this->options['whitelist_files']);
163+
164+
if ((!empty($this->options['blacklist_files']) || !empty($this->options['blacklist']))
165+
&& (!method_exists($filter, 'excludeFile') || !method_exists($filter, 'excludeDirectory'))
166+
) {
167+
throw new \RuntimeException(<<<TXT
168+
You are using "blacklist" or "blacklist_files" option parameter.
169+
Those parameters are now deprecated and will be removed in the
170+
next major release of this library.
171+
172+
To be able to continue using those parameters, you must explicitely
173+
install phpunit/php-code-coverage v10.x in your composer.json file:
174+
175+
compose require phpunit/php-code-coverage "^10.0"
176+
TXT);
177+
}
178+
162179
foreach ($this->options['blacklist'] as $option) {
163180
$settings = $this->filterDirectoryParams($option);
164-
foreach ((new FileIteratorFacade)->getFilesAsArray($directory, $suffix, $prefix) as $file) {
181+
foreach ((new FileIteratorFacade())->getFilesAsArray($directory, $suffix, $prefix) as $file) {
165182
$filter->excludeFile($file);
166183
}
167184
$filter->excludeDirectory($settings['directory'], $settings['suffix'], $settings['prefix']);
168185
}
169186

170-
$filter->includeFiles($this->options['whitelist_files']);
171-
172187
foreach ($this->options['blacklist_files'] as $option) {
173188
$filter->excludeFile($option);
174189
}

0 commit comments

Comments
 (0)