Skip to content

Commit

Permalink
[FEATURE] Add support for phpunit/php-code-coverage ^9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabRecht committed Aug 18, 2020
1 parent b9526f2 commit 16fb969
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ script:
jobs:
fast_finish: true
include:
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0"
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="~8.0.0"
Expand All @@ -74,6 +77,9 @@ jobs:
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="^5.0 ^6.0 ^7.0 ^8.0"
- stage: test
php: 7.3
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0"
- stage: test
php: 7.3
env: COVERAGE_VERSIONS="~8.0.0"
Expand Down Expand Up @@ -120,7 +126,7 @@ jobs:
- stage: ✔ with sonarqube scanner
if: type = push AND branch IN (master, pre-merge) AND env(SONAR_TOKEN) IS present AND fork = false
php: 7.3
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0 ~6.0.0 ~6.1.0 ~7.0.0 ~8.0.0"
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0"
before_install:
before_script:
script:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ext-dom": "*",
"ext-json": "*",
"ext-simplexml": "*",
"phpunit/php-code-coverage": ">=5.0 <9.0",
"phpunit/php-code-coverage": ">=5.0 <10.0",
"symfony/console": ">=2.7 <6.0",
"symfony/finder": ">=2.7 <6.0"
},
Expand Down
16 changes: 15 additions & 1 deletion src/PhpunitMerger/Command/CoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Nimut\PhpunitMerger\Command;

use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Filter as CodeCoverageFilter;
use SebastianBergmann\CodeCoverage\Report\Clover;
use SebastianBergmann\CodeCoverage\Report\Html\Facade;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -44,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$finder->files()
->in(realpath($input->getArgument('directory')));

$codeCoverage = new CodeCoverage();
$codeCoverage = $this->getCodeCoverage();

foreach ($finder as $file) {
$coverage = require $file->getRealPath();
Expand All @@ -63,6 +65,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

private function getCodeCoverage()
{
$driver = null;
$filter = null;
if (method_exists(Driver::class, 'forLineCoverage')) {
$filter = new CodeCoverageFilter();
$driver = Driver::forLineCoverage($filter);
}

return new CodeCoverage($driver, $filter);
}

private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $output, $file = null)
{
$writer = new Clover();
Expand Down

0 comments on commit 16fb969

Please sign in to comment.