Skip to content

Commit

Permalink
Merge pull request #888 from Slamdunk/backport_from_7.x
Browse files Browse the repository at this point in the history
Update PHPUnit compatibility to 10.5.33
  • Loading branch information
Slamdunk committed Sep 9, 2024
2 parents d4de825 + 02a3246 commit 7681556
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 79 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DOCKER_PHP_EXEC := docker compose run php
DOCKER_PHP_EXEC := docker compose run --rm php

SRCS := $(shell find ./src ./test -type f -not -path "*/tmp/*")

Expand All @@ -19,8 +19,8 @@ vendor: .env docker-compose.yml Dockerfile composer.json
docker compose build --pull
$(DOCKER_PHP_EXEC) composer update
$(DOCKER_PHP_EXEC) composer bump
touch vendor
mkdir .build-cache
touch --no-create $@
mkdir --parents .build-cache

.PHONY: csfix
csfix: vendor
Expand Down Expand Up @@ -62,7 +62,7 @@ code-coverage: coverage/junit.xml
--ignore-msi-with-no-mutations \
--min-msi=100 \
$(INFECTION_ARGS)

.PHONY: clean
clean:
git clean -dfX
Expand Down
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,6 @@ When a sub-process fails, the originating command is given in the output and can
to be run and debugged. All internal commands run with `--printer [...]\NullPhpunitPrinter` which silence the original
PHPUnit output: during a debugging run remove that option to restore the output and see what PHPUnit is doing.

## Windows

Windows users be sure to use the appropriate batch files.

An example being:

`vendor\bin\paratest.bat ...`

ParaTest assumes [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) for loading tests.

For convenience, ParaTest for Windows uses 79 columns mode to prevent blank lines in the standard
80x25 windows console.

## Caveats

1. Constants, static methods, static variables and everything exposed by test classes consumed by other test classes
Expand Down
3 changes: 0 additions & 3 deletions bin/paratest.bat

This file was deleted.

23 changes: 11 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@
"ext-pcre": "*",
"ext-reflection": "*",
"ext-simplexml": "*",
"fidry/cpu-core-counter": "^1.1.0",
"fidry/cpu-core-counter": "^1.2.0",
"jean85/pretty-package-versions": "^2.0.6",
"phpunit/php-code-coverage": "^10.1.14 || ^11.0.3",
"phpunit/php-file-iterator": "^4.1.0 || ^5.0.0",
"phpunit/php-timer": "^6.0.0 || ^7.0.0",
"phpunit/phpunit": "^10.5.20 || ^11.1.3",
"sebastian/environment": "^6.1.0 || ^7.1.0",
"symfony/console": "^6.4.7 || ^7.1.0",
"symfony/process": "^6.4.7 || ^7.1.0"
"phpunit/php-code-coverage": "^10.1.16",
"phpunit/php-file-iterator": "^4.1.0",
"phpunit/php-timer": "^6.0.0",
"phpunit/phpunit": "^10.5.33",
"sebastian/environment": "^6.1.0",
"symfony/console": "^6.4.7 || ^7.1.4",
"symfony/process": "^6.4.7 || ^7.1.3"
},
"require-dev": {
"ext-pcov": "*",
"ext-posix": "*",
"doctrine/coding-standard": "^12.0.0",
"phpstan/phpstan": "^1.11.2",
"phpstan/phpstan": "^1.12.3",
"phpstan/phpstan-deprecation-rules": "^1.2.0",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-strict-rules": "^1.6.0",
"squizlabs/php_codesniffer": "^3.10.1",
"symfony/filesystem": "^6.4.3 || ^7.1.0"
"squizlabs/php_codesniffer": "^3.10.2",
"symfony/filesystem": "^6.4.3 || ^7.1.2"
},
"autoload": {
"psr-4": {
Expand All @@ -73,7 +73,6 @@
},
"bin": [
"bin/paratest",
"bin/paratest.bat",
"bin/paratest_for_phpstorm"
],
"config": {
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ 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
4 changes: 1 addition & 3 deletions src/JUnit/LogMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
final class LogMerger
{
/** @param list<SplFileInfo> $junitFiles */
public function merge(array $junitFiles): TestSuite
public function merge(array $junitFiles): ?TestSuite
{
$mainSuite = null;
foreach ($junitFiles as $junitFile) {
Expand Down Expand Up @@ -67,8 +67,6 @@ public function merge(array $junitFiles): TestSuite
$mainSuite = $this->mergeSuites($mainSuite, $otherSuite);
}

assert($mainSuite !== null);

return $mainSuite;
}

Expand Down
4 changes: 3 additions & 1 deletion src/JUnit/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/** @internal */
final class Writer
{
private const TESTSUITES_NAME = 'PHPUnit tests';
private readonly DOMDocument $document;

public function __construct()
Expand All @@ -47,6 +48,7 @@ private function getXml(TestSuite $testSuite): string
{
$xmlTestsuites = $this->document->createElement('testsuites');
$xmlTestsuites->appendChild($this->createSuiteNode($testSuite));
$xmlTestsuites->setAttribute('name', self::TESTSUITES_NAME);
$this->document->appendChild($xmlTestsuites);

$xml = $this->document->saveXML();
Expand All @@ -58,7 +60,7 @@ private function getXml(TestSuite $testSuite): string
private function createSuiteNode(TestSuite $parentSuite): DOMElement
{
$suiteNode = $this->document->createElement('testsuite');
$suiteNode->setAttribute('name', $parentSuite->name);
$suiteNode->setAttribute('name', $parentSuite->name !== self::TESTSUITES_NAME ? $parentSuite->name : '');
if ($parentSuite->file !== '') {
$suiteNode->setAttribute('file', $parentSuite->file);
}
Expand Down
25 changes: 10 additions & 15 deletions src/WrapperRunner/ApplicationForWrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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 @@ -41,7 +40,6 @@
use function str_ends_with;
use function strpos;
use function substr;
use function version_compare;

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

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

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

(new TestSuiteFilterProcessor())->process($this->configuration, $testSuite);
Expand Down Expand Up @@ -201,7 +193,10 @@ private function bootstrap(): void
}

if (isset($this->testdoxFile)) {
$this->testdoxResultCollector = new TestResultCollector(EventFacade::instance());
$this->testdoxResultCollector = new TestResultCollector(
EventFacade::instance(),
$this->configuration->source(),
);
}

TestResultFacade::init();
Expand Down Expand Up @@ -231,7 +226,7 @@ public function end(): void
assert(isset($this->testdoxFile));
assert(isset($this->testdoxColumns));

(new TestDoxResultPrinter(DefaultPrinter::from($this->testdoxFile), $this->testdoxColor, $this->testdoxColumns))->print(
(new TestDoxResultPrinter(DefaultPrinter::from($this->testdoxFile), $this->testdoxColor))->print(
$this->testdoxResultCollector->testMethodsGroupedByClass(),
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/WrapperRunner/WrapperRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ private function complete(TestResult $testResultSum): int

$exitcode = (new ShellExitCodeCalculator())->calculate(
$this->options->configuration->failOnDeprecation(),
$this->options->configuration->failOnPhpunitDeprecation(),
$this->options->configuration->failOnEmptyTestSuite(),
$this->options->configuration->failOnIncomplete(),
$this->options->configuration->failOnNotice(),
Expand Down Expand Up @@ -345,6 +346,10 @@ private function generateLogs(): void
}

$testSuite = (new LogMerger())->merge($this->junitFiles);
if ($testSuite === null) {
return;
}

(new Writer())->write(
$testSuite,
$this->options->configuration->logfileJunit(),
Expand Down
2 changes: 2 additions & 0 deletions test/Unit/JUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testMergeJunitLogs(): void

self::assertNotSame([], $junitFiles);
$testSuite = (new LogMerger())->merge($junitFiles);
self::assertNotNull($testSuite);

$outputFile = $tmpDir . '/result.xml';
(new Writer())->write(
Expand All @@ -63,6 +64,7 @@ public function testHandleSpecialChars(): void

$junitLog = FIXTURES . '/special_chars/data-provider-with-special-chars.xml';
$testSuite = (new LogMerger())->merge([new SplFileInfo($junitLog)]);
self::assertNotNull($testSuite);

$outputFile = $tmpDir . '/result.xml';
(new Writer())->write(
Expand Down
5 changes: 0 additions & 5 deletions test/Unit/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use ParaTest\Tests\TestBase;
use PHPUnit\Framework\Attributes\CoversClass;

use function defined;
use function mt_rand;
use function str_replace;
use function uniqid;

use const DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -52,9 +50,6 @@ public function testAutoProcessesMode(): void
public function testPassthru(): void
{
$argv = ['--passthru-php' => "'-d' 'zend_extension=xdebug.so'"];
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$argv['--passthru-php'] = str_replace('\'', '"', $argv['--passthru-php']);
}

$options = $this->createOptionsFromArgv($argv);

Expand Down
13 changes: 9 additions & 4 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use function array_diff;
use function array_reverse;
use function array_unique;
use function defined;
use function explode;
use function file_get_contents;
use function file_put_contents;
Expand Down Expand Up @@ -223,9 +222,6 @@ public function testPassthrus(): void
self::assertSame(RunnerInterface::FAILURE_EXIT, $runnerResult->exitCode);

$this->bareOptions['--passthru-php'] = sprintf("'-d' 'highlight.comment=%s'", self::PASSTHRU_PHP_CUSTOM);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->bareOptions['--passthru-php'] = str_replace('\'', '"', $this->bareOptions['--passthru-php']);
}

$runnerResult = $this->runRunner();
self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
Expand Down Expand Up @@ -284,6 +280,15 @@ public function testTestdoxOutput(): void
);
}

public function testJunitOutputWithoutTests(): void
{
$this->bareOptions['path'] = $this->fixture('no_tests');
$this->bareOptions['--log-junit'] = $this->tmpDir . DIRECTORY_SEPARATOR . 'test-output.xml';
$runnerResult = $this->runRunner();

self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
}

public function testExitCodesPathWithoutTests(): void
{
$this->bareOptions['path'] = $this->fixture('no_tests');
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/combined.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="" tests="7" assertions="3" errors="1" failures="1" skipped="2" time="1.234567">
<testsuite name="ParaTest\Tests\fixtures\common_results\ErrorTest" file="./test/fixtures/common_results/ErrorTest.php" tests="1" assertions="0" errors="1" failures="0" skipped="0" time="1.234567">
<testcase name="testError" file="./test/fixtures/common_results/ErrorTest.php" line="13" class="ParaTest\Tests\fixtures\common_results\ErrorTest" classname="ParaTest.Tests.fixtures.common_results.ErrorTest" assertions="0" time="1.234567">
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/junit/ErrorTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\common_results\ErrorTest" file="./test/fixtures/common_results/ErrorTest.php" tests="1" assertions="0" errors="1" failures="0" skipped="0" time="1.234567">
<testcase name="testError" file="./test/fixtures/common_results/ErrorTest.php" line="13" class="ParaTest\Tests\fixtures\common_results\ErrorTest" classname="ParaTest.Tests.fixtures.common_results.ErrorTest" assertions="0" time="1.234567">
<error type="RuntimeException">ParaTest\Tests\fixtures\common_results\ErrorTest::testError
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/junit/FailureTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\common_results\FailureTest" file="./test/fixtures/common_results/FailureTest.php" tests="1" assertions="1" errors="0" failures="1" skipped="0" time="1.234567">
<testcase name="testFailure" file="./test/fixtures/common_results/FailureTest.php" line="12" class="ParaTest\Tests\fixtures\common_results\FailureTest" classname="ParaTest.Tests.fixtures.common_results.FailureTest" assertions="1" time="1.234567">
<failure type="PHPUnit\Framework\ExpectationFailedException">ParaTest\Tests\fixtures\common_results\FailureTest::testFailure
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/junit/IncompleteTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\common_results\IncompleteTest" file="./test/fixtures/common_results/IncompleteTest.php" tests="1" assertions="0" errors="0" failures="0" skipped="1" time="1.234567">
<testcase name="testIncomplete" file="./test/fixtures/common_results/IncompleteTest.php" line="12" class="ParaTest\Tests\fixtures\common_results\IncompleteTest" classname="ParaTest.Tests.fixtures.common_results.IncompleteTest" assertions="0" time="1.234567">
<skipped/>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/junit/RiskyTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\common_results\RiskyTest" file="./test/fixtures/common_results/RiskyTest.php" tests="1" assertions="0" errors="0" failures="0" skipped="0" time="1.234567">
<testcase name="testRisky" file="./test/fixtures/common_results/RiskyTest.php" line="12" class="ParaTest\Tests\fixtures\common_results\RiskyTest" classname="ParaTest.Tests.fixtures.common_results.RiskyTest" assertions="0" time="1.234567"/>
</testsuite>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/junit/SkippedTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\common_results\SkippedTest" file="./test/fixtures/common_results/SkippedTest.php" tests="1" assertions="0" errors="0" failures="0" skipped="1" time="1.234567">
<testcase name="testSkipped" file="./test/fixtures/common_results/SkippedTest.php" line="12" class="ParaTest\Tests\fixtures\common_results\SkippedTest" classname="ParaTest.Tests.fixtures.common_results.SkippedTest" assertions="0" time="1.234567">
<skipped/>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/junit/SuccessTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\common_results\SuccessTest" file="./test/fixtures/common_results/SuccessTest.php" tests="1" assertions="1" errors="0" failures="0" skipped="0" time="1.234567">
<testcase name="testSuccess" file="./test/fixtures/common_results/SuccessTest.php" line="12" class="ParaTest\Tests\fixtures\common_results\SuccessTest" classname="ParaTest.Tests.fixtures.common_results.SuccessTest" assertions="1" time="1.234567"/>
</testsuite>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/common_results/junit/WarningTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\common_results\WarningTest" file="./test/fixtures/common_results/WarningTest.php" tests="1" assertions="1" errors="0" failures="0" skipped="0" time="1.234567">
<testcase name="testWarning" file="./test/fixtures/common_results/WarningTest.php" line="16" class="ParaTest\Tests\fixtures\common_results\WarningTest" classname="ParaTest.Tests.fixtures.common_results.WarningTest" assertions="1" time="1.234567"/>
</testsuite>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuites name="PHPUnit tests">
<testsuite name="ParaTest\Tests\fixtures\special_chars\UnitTestWithDataProviderSpecialCharsTest" file="./test/fixtures/special_chars/UnitTestWithDataProviderSpecialCharsTest.php" tests="42" assertions="42" errors="0" failures="42" skipped="0" time="1.234567">
<testsuite name="ParaTest\Tests\fixtures\special_chars\UnitTestWithDataProviderSpecialCharsTest::testIsItFalse" tests="42" assertions="42" errors="0" failures="42" skipped="0" time="1.234567">
<testcase name="testIsItFalse with data set #0" file="./test/fixtures/special_chars/UnitTestWithDataProviderSpecialCharsTest.php" line="16" class="ParaTest\Tests\fixtures\special_chars\UnitTestWithDataProviderSpecialCharsTest" classname="ParaTest.Tests.fixtures.special_chars.UnitTestWithDataProviderSpecialCharsTest" assertions="1" time="1.234567">
Expand Down

0 comments on commit 7681556

Please sign in to comment.