Skip to content

Commit cd92bae

Browse files
authored
Merge pull request #58 from friends-of-phpspec/phpunit-10
Add compatibility with PHPUnit 10.
2 parents 02cdfd1 + 05abaa0 commit cd92bae

File tree

6 files changed

+92
-52
lines changed

6 files changed

+92
-52
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ name: "Continuous Integration"
88

99
jobs:
1010
run:
11-
name: "Grumphp"
1211
runs-on: ${{ matrix.operating-system }}
1312
strategy:
14-
fail-fast: false
13+
fail-fast: true
1514
matrix:
1615
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
1716
php-versions: ['7.3', '7.4', '8.0', '8.1']
1817
composer-versions: ['composer:v1', 'composer:v2']
18+
dependencies: ["lowest", "highest"]
1919

2020
steps:
2121
- name: Set git to use LF
@@ -26,14 +26,14 @@ jobs:
2626
- name: Checkout
2727
uses: actions/checkout@v2.3.1
2828
with:
29-
fetch-depth: 1
29+
fetch-depth: 10
3030

3131
- name: Install PHP
3232
uses: shivammathur/setup-php@v2
3333
with:
3434
php-version: ${{ matrix.php-versions }}
3535
tools: ${{ matrix.composer-versions }}
36-
extensions: mbstring, xdebug, pcov
36+
extensions: xdebug
3737

3838
- name: Get Composer Cache Directory
3939
id: composer-cache
@@ -46,17 +46,13 @@ jobs:
4646
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
4747
restore-keys: ${{ runner.os }}-composer-
4848

49-
- name: Install dependencies
50-
run: composer install --no-progress --prefer-dist --optimize-autoloader
49+
- name: "Install dependencies"
50+
uses: "ramsey/composer-install@v2"
51+
with:
52+
dependency-versions: "${{ matrix.dependencies }}"
5153

5254
- name: Run tests
5355
run: |
5456
composer run analyse
5557
composer run lint
5658
composer run test
57-
58-
- name: Send Scrutinizer data
59-
run: |
60-
wget https://scrutinizer-ci.com/ocular.phar
61-
php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
62-
continue-on-error: true
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
on:
4+
- pull_request
5+
- push
6+
7+
name: "Test Coverage"
8+
9+
jobs:
10+
run:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Set git to use LF
14+
run: |
15+
git config --global core.autocrlf false
16+
git config --global core.eol lf
17+
18+
- name: Checkout
19+
uses: actions/checkout@v2.3.1
20+
with:
21+
fetch-depth: 10
22+
23+
- name: Install PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: 8.1
27+
extensions: pcov
28+
29+
- name: Get Composer Cache Directory
30+
id: composer-cache
31+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
32+
33+
- name: Cache dependencies
34+
uses: actions/cache@v2
35+
with:
36+
path: ${{ steps.composer-cache.outputs.dir }}
37+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
38+
restore-keys: ${{ runner.os }}-composer-
39+
40+
- name: "Install dependencies"
41+
uses: "ramsey/composer-install@v2"
42+
43+
- name: Run tests
44+
run: composer run test-coverage
45+
46+
- name: Upload Scrutinizer coverage
47+
uses: sudo-bot/action-scrutinizer@latest
48+
with:
49+
cli-args: "--format=php-clover coverage/clover.xml"

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"require": {
4646
"php": ">= 7.3",
4747
"phpspec/phpspec": "^6.0 || ^7.0",
48-
"phpunit/php-code-coverage": "^9.0"
48+
"phpunit/php-code-coverage": "^9.2 || ^10.0"
4949
},
5050
"require-dev": {
5151
"phpstan/phpstan": "^1.5",
@@ -68,9 +68,10 @@
6868
]
6969
},
7070
"scripts": {
71-
"analyse": "phpstan analyse --level 8 src",
71+
"analyse": "phpstan analyse",
7272
"lint": "php-cs-fixer fix --dry-run src && php-cs-fixer fix --dry-run spec",
73-
"test": "phpspec run"
73+
"test": "phpspec run --no-coverage",
74+
"test-coverage": "phpspec run"
7475
},
7576
"extra": {
7677
"branch-alias": {

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
level: 8
3+
reportUnmatchedIgnoredErrors: false
4+
paths:
5+
- src
6+
ignoreErrors:
7+
# phpstan has hard time to check whenever we are using PHPUnit 10 or PHPUnit 9
8+
-
9+
message: '#Class SebastianBergmann\\CodeCoverage\\Report\\Text constructor invoked with 4 parameters, 1-3 required\.#'
10+
path: ./src/CodeCoverageExtension.php

spec/Listener/CodeCoverageListenerSpec.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use SebastianBergmann\CodeCoverage\CodeCoverage;
1313
use SebastianBergmann\CodeCoverage\Driver\Driver;
1414
use SebastianBergmann\CodeCoverage\Filter;
15-
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
1615
use stdClass;
1716

1817
/**
@@ -26,6 +25,13 @@
2625
*/
2726
class CodeCoverageListenerSpec extends ObjectBehavior
2827
{
28+
public function let(ConsoleIO $io, Driver $driver)
29+
{
30+
$codeCoverage = new CodeCoverage($driver->getWrappedObject(), new Filter());
31+
32+
$this->beConstructedWith($io, $codeCoverage, []);
33+
}
34+
2935
public function it_can_process_all_directory_filtering_options(SuiteEvent $event)
3036
{
3137
$this->setOptions([
@@ -85,28 +91,4 @@ public function it_will_throw_if_the_directory_parameter_is_missing(SuiteEvent $
8591
->shouldThrow(ConfigurationException::class)
8692
->during('beforeSuite', [$event]);
8793
}
88-
89-
public function let(ConsoleIO $io)
90-
{
91-
$codeCoverage = new CodeCoverage(new DriverStub(), new Filter());
92-
93-
$this->beConstructedWith($io, $codeCoverage, []);
94-
}
95-
}
96-
97-
class DriverStub extends Driver
98-
{
99-
public function nameAndVersion(): string
100-
{
101-
return 'DriverStub';
102-
}
103-
104-
public function start(bool $determineUnusedAndDead = true): void
105-
{
106-
}
107-
108-
public function stop(): RawCodeCoverageData
109-
{
110-
return RawCodeCoverageData::fromXdebugWithoutPathCoverage([]);
111-
}
11294
}

src/CodeCoverageExtension.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use SebastianBergmann\CodeCoverage\Driver\Selector;
2525
use SebastianBergmann\CodeCoverage\Filter;
2626
use SebastianBergmann\CodeCoverage\Report;
27+
use SebastianBergmann\CodeCoverage\Report\Thresholds;
2728
use SebastianBergmann\CodeCoverage\Version;
2829
use Symfony\Component\Console\Input\InputInterface;
2930
use Symfony\Component\Console\Input\InputOption;
@@ -119,12 +120,18 @@ public function load(ServiceContainer $container, array $params = []): void
119120

120121
break;
121122
case 'text':
122-
$reports['text'] = new Report\Text(
123-
$options['lower_upper_bound'],
124-
$options['high_lower_bound'],
125-
$options['show_uncovered_files'],
126-
$options['show_only_summary']
127-
);
123+
$reports['text'] = version_compare(Version::id(), '10.0.0', '>=') && class_exists(Thresholds::class)
124+
? new Report\Text(
125+
Thresholds::from($options['lower_upper_bound'], $options['high_lower_bound']),
126+
$options['show_uncovered_files'],
127+
$options['show_only_summary']
128+
)
129+
: new Report\Text(
130+
$options['lower_upper_bound'],
131+
$options['high_lower_bound'],
132+
$options['show_uncovered_files'],
133+
$options['show_only_summary']
134+
);
128135

129136
break;
130137
case 'xml':
@@ -152,14 +159,9 @@ public function load(ServiceContainer $container, array $params = []): void
152159
});
153160

154161
$container->define('event_dispatcher.listeners.code_coverage', static function (ServiceContainer $container) {
155-
$skipCoverage = false;
156-
157162
/** @var InputInterface $input */
158163
$input = $container->get('console.input');
159-
160-
if ($input->hasOption('no-coverage') && $input->getOption('no-coverage')) {
161-
$skipCoverage = true;
162-
}
164+
$skipCoverage = $input->hasOption('no-coverage') && $input->getOption('no-coverage');
163165

164166
/** @var ConsoleIO $consoleIO */
165167
$consoleIO = $container->get('console.io');

0 commit comments

Comments
 (0)