Skip to content

Commit

Permalink
[FEATURE] Add support for phpunit/php-code-coverage ^10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabRecht committed Oct 2, 2023
1 parent 5330371 commit ff24d85
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 101 deletions.
74 changes: 6 additions & 68 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ install:
echo "Running phpunit";
echo;
echo;
.Build/bin/phpunit --log-junit .Log/log/junit_$VERSION.xml --coverage-php .Log/coverage/coverage_$VERSION.cov --whitelist src/ tests/;
.Build/bin/phpunit --log-junit .Log/log/junit_$VERSION.xml --coverage-php .Log/coverage/coverage_$VERSION.cov --coverage-filter src/ tests/;
done
script:
Expand All @@ -66,80 +66,18 @@ jobs:
include:
- stage: test
php: 8.1.0
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
- stage: test
php: 8.0
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
env: COVERAGE_VERSIONS="~10.0.0 ~10.1.0"
- stage: test
php: 7.4
php: 8.1.0
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="~8.0.0"
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="~7.0.0"
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
- stage: test
php: 7.4
env: COVERAGE_VERSIONS="^5.0 ^6.0 ^7.0 ^8.0"
- stage: test
php: 7.3
php: 8.0
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
- stage: test
php: 7.3
env: COVERAGE_VERSIONS="~8.0.0"
- stage: test
php: 7.3
env: COVERAGE_VERSIONS="~7.0.0"
- stage: test
php: 7.3
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
- stage: test
php: 7.3
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
- stage: test
php: 7.3
env: COVERAGE_VERSIONS="^5.0 ^6.0 ^7.0 ^8.0"
- stage: test
php: 7.2
env: COVERAGE_VERSIONS="~7.0.0"
- stage: test
php: 7.2
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
- stage: test
php: 7.2
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
- stage: test
php: 7.2
env: COVERAGE_VERSIONS="^5.0 ^6.0 ^7.0"
- stage: test
php: 7.1
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
- stage: test
php: 7.1
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
- stage: test
php: 7.1
env: COVERAGE_VERSIONS="^5.0 ^6.0"
- stage: test
dist: xenial
php: 7.0
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
- stage: test
dist: xenial
php: 7.0
env: COVERAGE_VERSIONS="^5.0"

- 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="~9.0.0 ~9.1.0 ~9.2.0"
php: 8.1
env: COVERAGE_VERSIONS="~10.0.0 ~10.1.0"
before_script:
script:
- >
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
}
],
"require": {
"php": "^7.0.8 || ^8.0",
"php": "^8.0",
"ext-dom": "*",
"ext-json": "*",
"ext-simplexml": "*",
"phpunit/php-code-coverage": ">=5.0 <10.0",
"phpunit/php-code-coverage": "^9.0 || ^10.0",
"symfony/console": ">=2.7 <7.0",
"symfony/finder": ">=2.7 <7.0"
},
"require-dev": {
"phpunit/phpunit": ">=6.0 <10.0",
"phpunit/phpunit": "^9.3 || ^10.0",
"symfony/filesystem": ">=2.7 <7.0",
"phpspec/prophecy": "^1.0"
},
Expand Down
21 changes: 11 additions & 10 deletions src/PhpunitMerger/Command/CoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Nimut\PhpunitMerger\Command;

use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Filter as CodeCoverageFilter;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\Report\Clover;
use SebastianBergmann\CodeCoverage\Report\Html\Facade;
use SebastianBergmann\CodeCoverage\Report\Thresholds;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -82,14 +83,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

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

return new CodeCoverage($driver, $filter);
return new CodeCoverage((new Selector())->forLineCoverage($filter), $filter);
}

private function normalizeCoverage(CodeCoverage $coverage)
Expand All @@ -112,7 +108,12 @@ private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $

private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination, int $lowUpperBound, int $highLowerBound)
{
$writer = new Facade($lowUpperBound, $highLowerBound);
if (class_exists('SebastianBergmann\\CodeCoverage\\Report\\Thresholds')) {
$writer = new Facade('', null, Thresholds::from($lowUpperBound, $highLowerBound));
} else {
$writer = new Facade($lowUpperBound, $highLowerBound);
}

$writer->process($codeCoverage, $destination);
}
}
4 changes: 2 additions & 2 deletions tests/PhpunitMerger/Command/AbstractCommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function assertOutputFileNotExists()
$filesystem = new Filesystem();
$filesystem->remove($this->logDirectory . $this->outputFile);

$this->assertFileNotExists($this->logDirectory . $this->outputFile);
$this->assertFileDoesNotExist($this->logDirectory . $this->outputFile);
}

public function assertOutputDirectoryNotExists()
{
$filesystem = new Filesystem();
$filesystem->remove($this->logDirectory . dirname($this->outputFile));

$this->assertDirectoryNotExists($this->logDirectory . dirname($this->outputFile));
$this->assertDirectoryDoesNotExist($this->logDirectory . dirname($this->outputFile));
}
}
33 changes: 17 additions & 16 deletions tests/PhpunitMerger/Command/Coverage/CoverageCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Nimut\PhpunitMerger\Command\CoverageCommand;
use Nimut\PhpunitMerger\Tests\Command\AbstractCommandTestCase;
use Prophecy\Argument;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -28,11 +27,12 @@ public function testCoverageWritesOutputFile()
$this->logDirectory . $this->outputFile,
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::any())->shouldNotBeCalled();
$output = $this->getMockBuilder(OutputInterface::class)
->getMock();
$output->method('write')->willThrowException(new \Exception());

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
}
Expand All @@ -47,11 +47,11 @@ public function testCoverageWritesStandardOutput()
$this->logDirectory . 'coverage/',
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::type('string'))->shouldBeCalled();
$output = $this->getMockBuilder(OutputInterface::class)
->getMock();

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);
}

public function testCoverageWritesHtmlReport()
Expand All @@ -66,11 +66,11 @@ public function testCoverageWritesHtmlReport()
'--html=' . $this->logDirectory . dirname($this->outputFile),
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::type('string'))->shouldBeCalled();
$output = $this->getMockBuilder(OutputInterface::class)
->getMock();

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
}
Expand All @@ -89,11 +89,11 @@ public function testCoverageWritesHtmlReportWithCustomBounds()
'--highLowerBound=70',
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::type('string'))->shouldBeCalled();
$output = $this->getMockBuilder(OutputInterface::class)
->getMock();

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);

Expand Down Expand Up @@ -122,11 +122,12 @@ public function testCoverageWritesOutputFileAndHtmlReport()
$this->logDirectory . $this->outputFile,
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::any())->shouldNotBeCalled();
$output = $this->getMockBuilder(OutputInterface::class)
->getMock();
$output->method('write')->willThrowException(new \Exception());

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
$this->assertFileExists($this->logDirectory . dirname($this->outputFile) . '/index.html');
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpunitMerger/Command/Log/LogCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function testRunMergesCoverage()
$this->logDirectory . $this->outputFile,
]
);
$output = $this->prophesize(OutputInterface::class);
$output = $this->getMockBuilder(OutputInterface::class)->getMock();

$command = new LogCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
}
Expand Down

0 comments on commit ff24d85

Please sign in to comment.