Skip to content

Commit

Permalink
Merge pull request #58 from friends-of-phpspec/phpunit-10
Browse files Browse the repository at this point in the history
Add compatibility with PHPUnit 10.
  • Loading branch information
shulard authored Feb 22, 2023
2 parents 02cdfd1 + 05abaa0 commit cd92bae
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 52 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ name: "Continuous Integration"

jobs:
run:
name: "Grumphp"
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
fail-fast: true
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.3', '7.4', '8.0', '8.1']
composer-versions: ['composer:v1', 'composer:v2']
dependencies: ["lowest", "highest"]

steps:
- name: Set git to use LF
Expand All @@ -26,14 +26,14 @@ jobs:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 1
fetch-depth: 10

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: ${{ matrix.composer-versions }}
extensions: mbstring, xdebug, pcov
extensions: xdebug

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

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

- name: Run tests
run: |
composer run analyse
composer run lint
composer run test
- name: Send Scrutinizer data
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
continue-on-error: true
49 changes: 49 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

on:
- pull_request
- push

name: "Test Coverage"

jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 10

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: pcov

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"

- name: Run tests
run: composer run test-coverage

- name: Upload Scrutinizer coverage
uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover coverage/clover.xml"
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"require": {
"php": ">= 7.3",
"phpspec/phpspec": "^6.0 || ^7.0",
"phpunit/php-code-coverage": "^9.0"
"phpunit/php-code-coverage": "^9.2 || ^10.0"
},
"require-dev": {
"phpstan/phpstan": "^1.5",
Expand All @@ -68,9 +68,10 @@
]
},
"scripts": {
"analyse": "phpstan analyse --level 8 src",
"analyse": "phpstan analyse",
"lint": "php-cs-fixer fix --dry-run src && php-cs-fixer fix --dry-run spec",
"test": "phpspec run"
"test": "phpspec run --no-coverage",
"test-coverage": "phpspec run"
},
"extra": {
"branch-alias": {
Expand Down
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
level: 8
reportUnmatchedIgnoredErrors: false
paths:
- src
ignoreErrors:
# phpstan has hard time to check whenever we are using PHPUnit 10 or PHPUnit 9
-
message: '#Class SebastianBergmann\\CodeCoverage\\Report\\Text constructor invoked with 4 parameters, 1-3 required\.#'
path: ./src/CodeCoverageExtension.php
32 changes: 7 additions & 25 deletions spec/Listener/CodeCoverageListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
use stdClass;

/**
Expand All @@ -26,6 +25,13 @@
*/
class CodeCoverageListenerSpec extends ObjectBehavior
{
public function let(ConsoleIO $io, Driver $driver)
{
$codeCoverage = new CodeCoverage($driver->getWrappedObject(), new Filter());

$this->beConstructedWith($io, $codeCoverage, []);
}

public function it_can_process_all_directory_filtering_options(SuiteEvent $event)
{
$this->setOptions([
Expand Down Expand Up @@ -85,28 +91,4 @@ public function it_will_throw_if_the_directory_parameter_is_missing(SuiteEvent $
->shouldThrow(ConfigurationException::class)
->during('beforeSuite', [$event]);
}

public function let(ConsoleIO $io)
{
$codeCoverage = new CodeCoverage(new DriverStub(), new Filter());

$this->beConstructedWith($io, $codeCoverage, []);
}
}

class DriverStub extends Driver
{
public function nameAndVersion(): string
{
return 'DriverStub';
}

public function start(bool $determineUnusedAndDead = true): void
{
}

public function stop(): RawCodeCoverageData
{
return RawCodeCoverageData::fromXdebugWithoutPathCoverage([]);
}
}
26 changes: 14 additions & 12 deletions src/CodeCoverageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\Report;
use SebastianBergmann\CodeCoverage\Report\Thresholds;
use SebastianBergmann\CodeCoverage\Version;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -119,12 +120,18 @@ public function load(ServiceContainer $container, array $params = []): void

break;
case 'text':
$reports['text'] = new Report\Text(
$options['lower_upper_bound'],
$options['high_lower_bound'],
$options['show_uncovered_files'],
$options['show_only_summary']
);
$reports['text'] = version_compare(Version::id(), '10.0.0', '>=') && class_exists(Thresholds::class)
? new Report\Text(
Thresholds::from($options['lower_upper_bound'], $options['high_lower_bound']),
$options['show_uncovered_files'],
$options['show_only_summary']
)
: new Report\Text(
$options['lower_upper_bound'],
$options['high_lower_bound'],
$options['show_uncovered_files'],
$options['show_only_summary']
);

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

$container->define('event_dispatcher.listeners.code_coverage', static function (ServiceContainer $container) {
$skipCoverage = false;

/** @var InputInterface $input */
$input = $container->get('console.input');

if ($input->hasOption('no-coverage') && $input->getOption('no-coverage')) {
$skipCoverage = true;
}
$skipCoverage = $input->hasOption('no-coverage') && $input->getOption('no-coverage');

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

0 comments on commit cd92bae

Please sign in to comment.