Skip to content

Commit

Permalink
Merge pull request #838 from paratestphp/phpunit_11
Browse files Browse the repository at this point in the history
Add support for PHPUnit 11
  • Loading branch information
Slamdunk authored Feb 2, 2024
2 parents c8b661e + e4c70a0 commit 4ffc52e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 61 deletions.
83 changes: 41 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

steps:
- uses: "actions/checkout@v4"
Expand All @@ -40,7 +40,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

steps:
- uses: "actions/checkout@v4"
Expand All @@ -64,7 +64,6 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
dependencies:
Expand All @@ -86,51 +85,51 @@ jobs:
timeout-minutes: 3
run: "vendor/bin/phpunit --no-coverage --no-logging"

code-coverage:
name: "Code Coverage"
runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
- "8.2"

steps:
- uses: "actions/checkout@v4"
- uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: "${{ env.INI_VALUES }}"
- uses: "ramsey/composer-install@v2"

- run: "make test"
timeout-minutes: 3

- name: "Gather base branch for diff"
if: ${{ github.event_name == 'pull_request' }}
run: git fetch origin --no-tags --prune --depth=1 ${{ github.base_ref }} ${{ github.event.pull_request.base.sha }}

- name: "Infection on DIFF"
if: ${{ github.event_name == 'pull_request' }}
timeout-minutes: 30
run: make code-coverage INFECTION_ARGS="--logger-github"
env:
BASE_BRANCH: origin/${{ github.base_ref }}

- name: "Infection on complete code base"
if: ${{ github.event_name != 'pull_request' && !startsWith(github.ref_name, 'renovate/') }}
timeout-minutes: 30
run: "vendor/bin/infection run --ansi --threads=$(nproc) --skip-initial-tests --coverage=coverage"
env:
INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}
# code-coverage:
# name: "Code Coverage"
# runs-on: "ubuntu-latest"
# strategy:
# matrix:
# php-version:
# - "8.2"
#
# steps:
# - uses: "actions/checkout@v4"
# - uses: "shivammathur/setup-php@v2"
# with:
# coverage: "pcov"
# php-version: "${{ matrix.php-version }}"
# ini-values: "${{ env.INI_VALUES }}"
# - uses: "ramsey/composer-install@v2"
#
# - run: "make test"
# timeout-minutes: 3
#
# - name: "Gather base branch for diff"
# if: ${{ github.event_name == 'pull_request' }}
# run: git fetch origin --no-tags --prune --depth=1 ${{ github.base_ref }} ${{ github.event.pull_request.base.sha }}
#
# - name: "Infection on DIFF"
# if: ${{ github.event_name == 'pull_request' }}
# timeout-minutes: 30
# run: make code-coverage INFECTION_ARGS="--logger-github"
# env:
# BASE_BRANCH: origin/${{ github.base_ref }}
#
# - name: "Infection on complete code base"
# if: ${{ github.event_name != 'pull_request' && !startsWith(github.ref_name, 'renovate/') }}
# timeout-minutes: 30
# run: "vendor/bin/infection run --ansi --threads=$(nproc) --skip-initial-tests --coverage=coverage"
# env:
# INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}

coding-standards:
name: "Coding Standards"
runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

steps:
- uses: "actions/checkout@v4"
Expand All @@ -151,7 +150,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

steps:
- uses: "actions/checkout@v4"
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ ifeq ($(strip $(LOCAL_BASE_BRANCH)),)
endif
BASE_BRANCH ?= $(LOCAL_BASE_BRANCH)

all: csfix static-analysis code-coverage
#all: csfix static-analysis code-coverage
all: csfix static-analysis test
@echo "Done."

vendor: composer.json
Expand Down
2 changes: 2 additions & 0 deletions bin/phpunit-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
assert(isset($getopt['testresult-file']) && is_string($getopt['testresult-file']));
assert(!isset($getopt['teamcity-file']) || is_string($getopt['teamcity-file']));
assert(!isset($getopt['testdox-file']) || is_string($getopt['testdox-file']));
assert(!isset($getopt['testdox-columns']) || is_int($getopt['testdox-columns']));

assert(isset($getopt['phpunit-argv']) && is_string($getopt['phpunit-argv']));
$phpunitArgv = unserialize($getopt['phpunit-argv'], ['allowed_classes' => false]);
Expand All @@ -54,6 +55,7 @@
$getopt['teamcity-file'] ?? null,
$getopt['testdox-file'] ?? null,
isset($getopt['testdox-color']),
$getopt['testdox-columns'] ?? null,
);

while (true) {
Expand Down
21 changes: 10 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,31 @@
}
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"php": "~8.2.0 || ~8.3.0",
"ext-dom": "*",
"ext-pcre": "*",
"ext-reflection": "*",
"ext-simplexml": "*",
"fidry/cpu-core-counter": "^0.5.1 || ^1.0.0",
"fidry/cpu-core-counter": "^1.0.0",
"jean85/pretty-package-versions": "^2.0.5",
"phpunit/php-code-coverage": "^10.1.11",
"phpunit/php-file-iterator": "^4.1.0",
"phpunit/php-timer": "^6.0",
"phpunit/phpunit": "^10.5.9",
"sebastian/environment": "^6.0.1",
"symfony/console": "^6.4.2 || ^7.0.2",
"symfony/process": "^6.4.2 || ^7.0.2"
"phpunit/php-code-coverage": "^10.1.11 || ^11.0.0",
"phpunit/php-file-iterator": "^4.1.0 || ^5.0.0",
"phpunit/php-timer": "^6.0.0 || ^7.0.0",
"phpunit/phpunit": "^10.5.9 || ^11.0.0",
"sebastian/environment": "^6.0.1 || ^7.0.0",
"symfony/console": "^6.4.3 || ^7.0.3",
"symfony/process": "^6.4.3 || ^7.0.3"
},
"require-dev": {
"ext-pcov": "*",
"ext-posix": "*",
"doctrine/coding-standard": "^12.0.0",
"infection/infection": "^0.27.9",
"phpstan/phpstan": "^1.10.57",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-phpunit": "^1.3.15",
"phpstan/phpstan-strict-rules": "^1.5.2",
"squizlabs/php_codesniffer": "^3.8.1",
"symfony/filesystem": "^6.4.0 || ^7.0.0"
"symfony/filesystem": "^6.4.3 || ^7.0.3"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ parameters:
count: 1
path: src/Options.php

-
message: "#^Call to an undefined method PHPUnit\\\\Metadata\\\\Api\\\\CodeCoverage\\:\\:linesToBeIgnored\\(\\)\\.$#"
count: 1
path: src/WrapperRunner/ApplicationForWrapperWorker.php

-
message: "#^Call to an undefined method PHPUnit\\\\Runner\\\\Filter\\\\Factory\\:\\:addNameFilter\\(\\)\\.$#"
count: 1
path: src/WrapperRunner/ApplicationForWrapperWorker.php

-
message: "#^Match expression does not handle remaining value\\: string$#"
count: 1
Expand Down
23 changes: 17 additions & 6 deletions src/WrapperRunner/ApplicationForWrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPUnit\Runner\Filter\Factory;
use PHPUnit\Runner\TestSuiteLoader;
use PHPUnit\Runner\TestSuiteSorter;
use PHPUnit\Runner\Version;
use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade;
use PHPUnit\TextUI\Configuration\Builder;
use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry;
Expand All @@ -40,6 +41,7 @@
use function str_ends_with;
use function strpos;
use function substr;
use function version_compare;

/**
* @internal
Expand All @@ -61,6 +63,7 @@ public function __construct(
private readonly ?string $teamcityFile,
private readonly ?string $testdoxFile,
private readonly bool $testdoxColor,
private readonly ?int $testdoxColumns,
) {
}

Expand All @@ -72,7 +75,12 @@ public function runTest(string $testPath): int
$filter = new Factory();
$name = substr($testPath, $null + 1);
assert($name !== '');
$filter->addNameFilter($name);
if (version_compare(Version::id(), '11.0.0') >= 0) {
$filter->addIncludeNameFilter($name);
} else {
$filter->addNameFilter($name);
}

$testPath = substr($testPath, 0, $null);
}

Expand All @@ -86,10 +94,12 @@ public function runTest(string $testPath): int
$testSuite = TestSuite::fromClassReflector($testSuiteRefl);
}

if (CodeCoverage::instance()->isActive()) {
CodeCoverage::instance()->ignoreLines(
(new CodeCoverageMetadataApi())->linesToBeIgnored($testSuite),
);
if (version_compare(Version::id(), '11.0.0') < 0) {
if (CodeCoverage::instance()->isActive()) {
CodeCoverage::instance()->ignoreLines(
(new CodeCoverageMetadataApi())->linesToBeIgnored($testSuite),
);
}
}

(new TestSuiteFilterProcessor())->process($this->configuration, $testSuite);
Expand Down Expand Up @@ -219,8 +229,9 @@ public function end(): void
$result = TestResultFacade::result();
if (isset($this->testdoxResultCollector)) {
assert(isset($this->testdoxFile));
assert(isset($this->testdoxColumns));

(new TestDoxResultPrinter(DefaultPrinter::from($this->testdoxFile), $this->testdoxColor))->print(
(new TestDoxResultPrinter(DefaultPrinter::from($this->testdoxFile), $this->testdoxColor, $this->testdoxColumns))->print(
$this->testdoxResultCollector->testMethodsGroupedByClass(),
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/WrapperRunner/WrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public function __construct(
if ($options->configuration->colors()) {
$parameters[] = '--testdox-color';
}

$parameters[] = '--testdox-columns';
$parameters[] = (string) $options->configuration->columns();
}

$phpunitArguments = [$options->phpunit];
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function testTeamcityOutput(): void
self::assertNotFalse($format);

$output = $result->output;
$output = preg_replace("/^Processes: \\d+\nRuntime: PHP \\d+.\\d+.\\d+(-dev)?\n\n/", '', $output, 1, $count);
$output = preg_replace("/^Processes: \\d+\nRuntime: PHP \\d+.\\d+.\\d+(-\w+)?\n\n/", '', $output, 1, $count);
self::assertSame(1, $count);
self::assertNotNull($output);

Expand Down

0 comments on commit 4ffc52e

Please sign in to comment.