Skip to content

Commit

Permalink
deprecation: blacklist and blacklist_files are now deprecated.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shulard committed Jul 15, 2024
1 parent 61b4936 commit 175d840
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/Listener/CodeCoverageListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function let(ConsoleIO $io, Driver $driver)
public function it_can_process_all_directory_filtering_options(SuiteEvent $event)
{
$this->setOptions([
'blacklist' => [
'whitelist' => [
'src',
['directory' => 'src', 'suffix' => 'Spec.php', 'prefix' => 'Get'],
['directory' => 'src', 'suffix' => 'Test.php'],
Expand Down
23 changes: 19 additions & 4 deletions src/Listener/CodeCoverageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
$this->reports = $reports;
$this->options = [
'whitelist' => ['src', 'lib'],
'blacklist' => ['test', 'vendor', 'spec'],
'blacklist' => [],
'whitelist_files' => [],
'blacklist_files' => [],
'output' => ['html' => 'coverage'],
Expand Down Expand Up @@ -159,16 +159,31 @@ public function beforeSuite(SuiteEvent $event): void
}
}

$filter->includeFiles($this->options['whitelist_files']);

if ((!empty($this->options['blacklist_files']) || !empty($this->options['blacklist']))
&& (!method_exists($filter, 'excludeFile') || !method_exists($filter, 'excludeDirectory'))
) {
throw new \RuntimeException(<<<TXT
You are using "blacklist" or "blacklist_files" option parameter.
Those parameters are now deprecated and will be removed in the
next major release of this library.
To be able to continue using those parameters, you must explicitely
install phpunit/php-code-coverage v10.x in your composer.json file:
compose require phpunit/php-code-coverage "^10.0"
TXT);
}

foreach ($this->options['blacklist'] as $option) {
$settings = $this->filterDirectoryParams($option);
foreach ((new FileIteratorFacade)->getFilesAsArray($directory, $suffix, $prefix) as $file) {
foreach ((new FileIteratorFacade())->getFilesAsArray($directory, $suffix, $prefix) as $file) {

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.4, composer:v2, lowest)

Undefined variable: $directory

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.4, composer:v2, lowest)

Undefined variable: $prefix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, lowest)

Undefined variable: $directory

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.4, composer:v2, lowest)

Undefined variable: $suffix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, lowest)

Undefined variable: $prefix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, lowest)

Undefined variable: $suffix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 8.1, composer:v2, lowest)

Undefined variable: $directory

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 8.1, composer:v2, lowest)

Undefined variable: $prefix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 8.1, composer:v2, lowest)

Undefined variable: $suffix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.4, composer:v2, highest)

Undefined variable: $directory

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.4, composer:v2, highest)

Undefined variable: $prefix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.4, composer:v2, highest)

Undefined variable: $suffix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 8.0, composer:v2, lowest)

Undefined variable: $directory

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 8.0, composer:v2, lowest)

Undefined variable: $prefix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 8.0, composer:v2, lowest)

Undefined variable: $suffix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, highest)

Undefined variable: $directory

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, highest)

Undefined variable: $prefix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, highest)

Undefined variable: $suffix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, highest)

Undefined variable: $directory

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, highest)

Undefined variable: $prefix

Check failure on line 181 in src/Listener/CodeCoverageListener.php

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 7.3, composer:v2, highest)

Undefined variable: $suffix
$filter->excludeFile($file);
}
$filter->excludeDirectory($settings['directory'], $settings['suffix'], $settings['prefix']);
}

$filter->includeFiles($this->options['whitelist_files']);

foreach ($this->options['blacklist_files'] as $option) {
$filter->excludeFile($option);
}
Expand Down

0 comments on commit 175d840

Please sign in to comment.