Skip to content

Commit ff24d85

Browse files
committed
[FEATURE] Add support for phpunit/php-code-coverage ^10.0
1 parent 5330371 commit ff24d85

File tree

6 files changed

+41
-101
lines changed

6 files changed

+41
-101
lines changed

.travis.yml

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ install:
4242
echo "Running phpunit";
4343
echo;
4444
echo;
45-
.Build/bin/phpunit --log-junit .Log/log/junit_$VERSION.xml --coverage-php .Log/coverage/coverage_$VERSION.cov --whitelist src/ tests/;
45+
.Build/bin/phpunit --log-junit .Log/log/junit_$VERSION.xml --coverage-php .Log/coverage/coverage_$VERSION.cov --coverage-filter src/ tests/;
4646
done
4747
4848
script:
@@ -66,80 +66,18 @@ jobs:
6666
include:
6767
- stage: test
6868
php: 8.1.0
69-
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
70-
- stage: test
71-
php: 8.0
72-
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
69+
env: COVERAGE_VERSIONS="~10.0.0 ~10.1.0"
7370
- stage: test
74-
php: 7.4
71+
php: 8.1.0
7572
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
7673
- stage: test
77-
php: 7.4
78-
env: COVERAGE_VERSIONS="~8.0.0"
79-
- stage: test
80-
php: 7.4
81-
env: COVERAGE_VERSIONS="~7.0.0"
82-
- stage: test
83-
php: 7.4
84-
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
85-
- stage: test
86-
php: 7.4
87-
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
88-
- stage: test
89-
php: 7.4
90-
env: COVERAGE_VERSIONS="^5.0 ^6.0 ^7.0 ^8.0"
91-
- stage: test
92-
php: 7.3
74+
php: 8.0
9375
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
94-
- stage: test
95-
php: 7.3
96-
env: COVERAGE_VERSIONS="~8.0.0"
97-
- stage: test
98-
php: 7.3
99-
env: COVERAGE_VERSIONS="~7.0.0"
100-
- stage: test
101-
php: 7.3
102-
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
103-
- stage: test
104-
php: 7.3
105-
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
106-
- stage: test
107-
php: 7.3
108-
env: COVERAGE_VERSIONS="^5.0 ^6.0 ^7.0 ^8.0"
109-
- stage: test
110-
php: 7.2
111-
env: COVERAGE_VERSIONS="~7.0.0"
112-
- stage: test
113-
php: 7.2
114-
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
115-
- stage: test
116-
php: 7.2
117-
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
118-
- stage: test
119-
php: 7.2
120-
env: COVERAGE_VERSIONS="^5.0 ^6.0 ^7.0"
121-
- stage: test
122-
php: 7.1
123-
env: COVERAGE_VERSIONS="~6.0.0 ~6.1.0"
124-
- stage: test
125-
php: 7.1
126-
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
127-
- stage: test
128-
php: 7.1
129-
env: COVERAGE_VERSIONS="^5.0 ^6.0"
130-
- stage: test
131-
dist: xenial
132-
php: 7.0
133-
env: COVERAGE_VERSIONS="~5.0.0 ~5.1.0 ~5.2.0 ~5.3.0"
134-
- stage: test
135-
dist: xenial
136-
php: 7.0
137-
env: COVERAGE_VERSIONS="^5.0"
13876

13977
- stage: ✔ with sonarqube scanner
14078
if: type = push AND branch IN (master, pre-merge) AND env(SONAR_TOKEN) IS present AND fork = false
141-
php: 7.3
142-
env: COVERAGE_VERSIONS="~9.0.0 ~9.1.0 ~9.2.0"
79+
php: 8.1
80+
env: COVERAGE_VERSIONS="~10.0.0 ~10.1.0"
14381
before_script:
14482
script:
14583
- >

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
}
2727
],
2828
"require": {
29-
"php": "^7.0.8 || ^8.0",
29+
"php": "^8.0",
3030
"ext-dom": "*",
3131
"ext-json": "*",
3232
"ext-simplexml": "*",
33-
"phpunit/php-code-coverage": ">=5.0 <10.0",
33+
"phpunit/php-code-coverage": "^9.0 || ^10.0",
3434
"symfony/console": ">=2.7 <7.0",
3535
"symfony/finder": ">=2.7 <7.0"
3636
},
3737
"require-dev": {
38-
"phpunit/phpunit": ">=6.0 <10.0",
38+
"phpunit/phpunit": "^9.3 || ^10.0",
3939
"symfony/filesystem": ">=2.7 <7.0",
4040
"phpspec/prophecy": "^1.0"
4141
},

src/PhpunitMerger/Command/CoverageCommand.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
namespace Nimut\PhpunitMerger\Command;
66

77
use SebastianBergmann\CodeCoverage\CodeCoverage;
8-
use SebastianBergmann\CodeCoverage\Driver\Driver;
9-
use SebastianBergmann\CodeCoverage\Filter as CodeCoverageFilter;
8+
use SebastianBergmann\CodeCoverage\Driver\Selector;
9+
use SebastianBergmann\CodeCoverage\Filter;
1010
use SebastianBergmann\CodeCoverage\Report\Clover;
1111
use SebastianBergmann\CodeCoverage\Report\Html\Facade;
12+
use SebastianBergmann\CodeCoverage\Report\Thresholds;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputArgument;
1415
use Symfony\Component\Console\Input\InputInterface;
@@ -82,14 +83,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8283

8384
private function getCodeCoverage()
8485
{
85-
$driver = null;
86-
$filter = null;
87-
if (method_exists(Driver::class, 'forLineCoverage')) {
88-
$filter = new CodeCoverageFilter();
89-
$driver = Driver::forLineCoverage($filter);
90-
}
86+
$filter = new Filter();
9187

92-
return new CodeCoverage($driver, $filter);
88+
return new CodeCoverage((new Selector())->forLineCoverage($filter), $filter);
9389
}
9490

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

113109
private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination, int $lowUpperBound, int $highLowerBound)
114110
{
115-
$writer = new Facade($lowUpperBound, $highLowerBound);
111+
if (class_exists('SebastianBergmann\\CodeCoverage\\Report\\Thresholds')) {
112+
$writer = new Facade('', null, Thresholds::from($lowUpperBound, $highLowerBound));
113+
} else {
114+
$writer = new Facade($lowUpperBound, $highLowerBound);
115+
}
116+
116117
$writer->process($codeCoverage, $destination);
117118
}
118119
}

tests/PhpunitMerger/Command/AbstractCommandTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public function assertOutputFileNotExists()
2424
$filesystem = new Filesystem();
2525
$filesystem->remove($this->logDirectory . $this->outputFile);
2626

27-
$this->assertFileNotExists($this->logDirectory . $this->outputFile);
27+
$this->assertFileDoesNotExist($this->logDirectory . $this->outputFile);
2828
}
2929

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

35-
$this->assertDirectoryNotExists($this->logDirectory . dirname($this->outputFile));
35+
$this->assertDirectoryDoesNotExist($this->logDirectory . dirname($this->outputFile));
3636
}
3737
}

tests/PhpunitMerger/Command/Coverage/CoverageCommandTest.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Nimut\PhpunitMerger\Command\CoverageCommand;
88
use Nimut\PhpunitMerger\Tests\Command\AbstractCommandTestCase;
9-
use Prophecy\Argument;
109
use Symfony\Component\Console\Input\ArgvInput;
1110
use Symfony\Component\Console\Output\OutputInterface;
1211

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

3434
$command = new CoverageCommand();
35-
$command->run($input, $output->reveal());
35+
$command->run($input, $output);
3636

3737
$this->assertFileExists($this->logDirectory . $this->outputFile);
3838
}
@@ -47,11 +47,11 @@ public function testCoverageWritesStandardOutput()
4747
$this->logDirectory . 'coverage/',
4848
]
4949
);
50-
$output = $this->prophesize(OutputInterface::class);
51-
$output->write(Argument::type('string'))->shouldBeCalled();
50+
$output = $this->getMockBuilder(OutputInterface::class)
51+
->getMock();
5252

5353
$command = new CoverageCommand();
54-
$command->run($input, $output->reveal());
54+
$command->run($input, $output);
5555
}
5656

5757
public function testCoverageWritesHtmlReport()
@@ -66,11 +66,11 @@ public function testCoverageWritesHtmlReport()
6666
'--html=' . $this->logDirectory . dirname($this->outputFile),
6767
]
6868
);
69-
$output = $this->prophesize(OutputInterface::class);
70-
$output->write(Argument::type('string'))->shouldBeCalled();
69+
$output = $this->getMockBuilder(OutputInterface::class)
70+
->getMock();
7171

7272
$command = new CoverageCommand();
73-
$command->run($input, $output->reveal());
73+
$command->run($input, $output);
7474

7575
$this->assertFileExists($this->logDirectory . $this->outputFile);
7676
}
@@ -89,11 +89,11 @@ public function testCoverageWritesHtmlReportWithCustomBounds()
8989
'--highLowerBound=70',
9090
]
9191
);
92-
$output = $this->prophesize(OutputInterface::class);
93-
$output->write(Argument::type('string'))->shouldBeCalled();
92+
$output = $this->getMockBuilder(OutputInterface::class)
93+
->getMock();
9494

9595
$command = new CoverageCommand();
96-
$command->run($input, $output->reveal());
96+
$command->run($input, $output);
9797

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

@@ -122,11 +122,12 @@ public function testCoverageWritesOutputFileAndHtmlReport()
122122
$this->logDirectory . $this->outputFile,
123123
]
124124
);
125-
$output = $this->prophesize(OutputInterface::class);
126-
$output->write(Argument::any())->shouldNotBeCalled();
125+
$output = $this->getMockBuilder(OutputInterface::class)
126+
->getMock();
127+
$output->method('write')->willThrowException(new \Exception());
127128

128129
$command = new CoverageCommand();
129-
$command->run($input, $output->reveal());
130+
$command->run($input, $output);
130131

131132
$this->assertFileExists($this->logDirectory . $this->outputFile);
132133
$this->assertFileExists($this->logDirectory . dirname($this->outputFile) . '/index.html');

tests/PhpunitMerger/Command/Log/LogCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public function testRunMergesCoverage()
2727
$this->logDirectory . $this->outputFile,
2828
]
2929
);
30-
$output = $this->prophesize(OutputInterface::class);
30+
$output = $this->getMockBuilder(OutputInterface::class)->getMock();
3131

3232
$command = new LogCommand();
33-
$command->run($input, $output->reveal());
33+
$command->run($input, $output);
3434

3535
$this->assertFileExists($this->logDirectory . $this->outputFile);
3636
}

0 commit comments

Comments
 (0)