From c3a7aa45295df9d59864fad531e640b9fe5234f1 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 3 Jun 2024 14:42:51 +0200 Subject: [PATCH 1/7] Fix `mkdir` on branch switching --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a798a2a8..b5a92bb9 100644 --- a/Makefile +++ b/Makefile @@ -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 From 54894398c755fb3aa32d32d8f63895a335a0de9a Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 12 Jun 2024 15:02:43 +0200 Subject: [PATCH 2/7] Drop Windows support (#861) --- README.md | 13 ------------- bin/paratest.bat | 3 --- composer.json | 1 - test/Unit/OptionsTest.php | 5 ----- test/Unit/WrapperRunner/WrapperRunnerTest.php | 4 ---- 5 files changed, 26 deletions(-) delete mode 100644 bin/paratest.bat diff --git a/README.md b/README.md index f5a8fe5a..5dd6f1d3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/paratest.bat b/bin/paratest.bat deleted file mode 100644 index 15c8a5a0..00000000 --- a/bin/paratest.bat +++ /dev/null @@ -1,3 +0,0 @@ -@ECHO OFF -SET BIN_TARGET=%~dp0\"../bin"\paratest -php "%BIN_TARGET%" %* \ No newline at end of file diff --git a/composer.json b/composer.json index c9090bfd..697378a2 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,6 @@ }, "bin": [ "bin/paratest", - "bin/paratest.bat", "bin/paratest_for_phpstorm" ], "config": { diff --git a/test/Unit/OptionsTest.php b/test/Unit/OptionsTest.php index f160976a..f1c7a61c 100644 --- a/test/Unit/OptionsTest.php +++ b/test/Unit/OptionsTest.php @@ -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; @@ -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); diff --git a/test/Unit/WrapperRunner/WrapperRunnerTest.php b/test/Unit/WrapperRunner/WrapperRunnerTest.php index b6d5bb30..72abab4f 100644 --- a/test/Unit/WrapperRunner/WrapperRunnerTest.php +++ b/test/Unit/WrapperRunner/WrapperRunnerTest.php @@ -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; @@ -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); From 7649b36c224527003c8e0d7d7c6ca70af647f68b Mon Sep 17 00:00:00 2001 From: FotoCadeau Hylke Date: Tue, 6 Aug 2024 14:34:02 +0200 Subject: [PATCH 3/7] Fix `LogMerger` when no log is created (#867) --- Makefile | 4 ++-- src/JUnit/LogMerger.php | 4 +--- src/WrapperRunner/WrapperRunner.php | 4 ++++ test/Unit/JUnitTest.php | 2 ++ test/Unit/WrapperRunner/WrapperRunnerTest.php | 9 +++++++++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b5a92bb9..583bd54d 100644 --- a/Makefile +++ b/Makefile @@ -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/*") @@ -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 diff --git a/src/JUnit/LogMerger.php b/src/JUnit/LogMerger.php index ddf2f4f1..7b28df37 100644 --- a/src/JUnit/LogMerger.php +++ b/src/JUnit/LogMerger.php @@ -18,7 +18,7 @@ final class LogMerger { /** @param list $junitFiles */ - public function merge(array $junitFiles): TestSuite + public function merge(array $junitFiles): ?TestSuite { $mainSuite = null; foreach ($junitFiles as $junitFile) { @@ -67,8 +67,6 @@ public function merge(array $junitFiles): TestSuite $mainSuite = $this->mergeSuites($mainSuite, $otherSuite); } - assert($mainSuite !== null); - return $mainSuite; } diff --git a/src/WrapperRunner/WrapperRunner.php b/src/WrapperRunner/WrapperRunner.php index e854dfcd..f6fc5008 100644 --- a/src/WrapperRunner/WrapperRunner.php +++ b/src/WrapperRunner/WrapperRunner.php @@ -345,6 +345,10 @@ private function generateLogs(): void } $testSuite = (new LogMerger())->merge($this->junitFiles); + if ($testSuite === null) { + return; + } + (new Writer())->write( $testSuite, $this->options->configuration->logfileJunit(), diff --git a/test/Unit/JUnitTest.php b/test/Unit/JUnitTest.php index 70ac705c..b4a60c40 100644 --- a/test/Unit/JUnitTest.php +++ b/test/Unit/JUnitTest.php @@ -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( @@ -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( diff --git a/test/Unit/WrapperRunner/WrapperRunnerTest.php b/test/Unit/WrapperRunner/WrapperRunnerTest.php index 72abab4f..5606897f 100644 --- a/test/Unit/WrapperRunner/WrapperRunnerTest.php +++ b/test/Unit/WrapperRunner/WrapperRunnerTest.php @@ -280,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'); From 637064e49faeaeb2dc9df5ce1a4bf30f4295ff1c Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Tue, 3 Sep 2024 14:47:03 +0200 Subject: [PATCH 4/7] Update PHPUnit compatibility to 11.3.2 (#879) --- src/JUnit/Writer.php | 4 +++- src/WrapperRunner/ApplicationForWrapperWorker.php | 5 ++++- test/fixtures/common_results/combined.xml | 2 +- test/fixtures/common_results/junit/ErrorTest.xml | 2 +- test/fixtures/common_results/junit/FailureTest.xml | 2 +- test/fixtures/common_results/junit/IncompleteTest.xml | 2 +- test/fixtures/common_results/junit/RiskyTest.xml | 2 +- test/fixtures/common_results/junit/SkippedTest.xml | 2 +- test/fixtures/common_results/junit/SuccessTest.xml | 2 +- test/fixtures/common_results/junit/WarningTest.xml | 2 +- .../special_chars/data-provider-with-special-chars.xml | 2 +- 11 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/JUnit/Writer.php b/src/JUnit/Writer.php index 8ffe5515..3e09b69c 100644 --- a/src/JUnit/Writer.php +++ b/src/JUnit/Writer.php @@ -23,6 +23,7 @@ /** @internal */ final class Writer { + private const TESTSUITES_NAME = 'PHPUnit tests'; private readonly DOMDocument $document; public function __construct() @@ -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(); @@ -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); } diff --git a/src/WrapperRunner/ApplicationForWrapperWorker.php b/src/WrapperRunner/ApplicationForWrapperWorker.php index 9c61bbc6..7748f03b 100644 --- a/src/WrapperRunner/ApplicationForWrapperWorker.php +++ b/src/WrapperRunner/ApplicationForWrapperWorker.php @@ -201,7 +201,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(); diff --git a/test/fixtures/common_results/combined.xml b/test/fixtures/common_results/combined.xml index 8c82e07d..70ed23c3 100644 --- a/test/fixtures/common_results/combined.xml +++ b/test/fixtures/common_results/combined.xml @@ -1,5 +1,5 @@ - + diff --git a/test/fixtures/common_results/junit/ErrorTest.xml b/test/fixtures/common_results/junit/ErrorTest.xml index b34d0008..6de63f13 100644 --- a/test/fixtures/common_results/junit/ErrorTest.xml +++ b/test/fixtures/common_results/junit/ErrorTest.xml @@ -1,5 +1,5 @@ - + ParaTest\Tests\fixtures\common_results\ErrorTest::testError diff --git a/test/fixtures/common_results/junit/FailureTest.xml b/test/fixtures/common_results/junit/FailureTest.xml index f8994736..4802857d 100644 --- a/test/fixtures/common_results/junit/FailureTest.xml +++ b/test/fixtures/common_results/junit/FailureTest.xml @@ -1,5 +1,5 @@ - + ParaTest\Tests\fixtures\common_results\FailureTest::testFailure diff --git a/test/fixtures/common_results/junit/IncompleteTest.xml b/test/fixtures/common_results/junit/IncompleteTest.xml index 01513a83..577444a6 100644 --- a/test/fixtures/common_results/junit/IncompleteTest.xml +++ b/test/fixtures/common_results/junit/IncompleteTest.xml @@ -1,5 +1,5 @@ - + diff --git a/test/fixtures/common_results/junit/RiskyTest.xml b/test/fixtures/common_results/junit/RiskyTest.xml index 5149e267..7226cbba 100644 --- a/test/fixtures/common_results/junit/RiskyTest.xml +++ b/test/fixtures/common_results/junit/RiskyTest.xml @@ -1,5 +1,5 @@ - + diff --git a/test/fixtures/common_results/junit/SkippedTest.xml b/test/fixtures/common_results/junit/SkippedTest.xml index 3254b36b..202dd04b 100644 --- a/test/fixtures/common_results/junit/SkippedTest.xml +++ b/test/fixtures/common_results/junit/SkippedTest.xml @@ -1,5 +1,5 @@ - + diff --git a/test/fixtures/common_results/junit/SuccessTest.xml b/test/fixtures/common_results/junit/SuccessTest.xml index 6b44f389..99a6f779 100644 --- a/test/fixtures/common_results/junit/SuccessTest.xml +++ b/test/fixtures/common_results/junit/SuccessTest.xml @@ -1,5 +1,5 @@ - + diff --git a/test/fixtures/common_results/junit/WarningTest.xml b/test/fixtures/common_results/junit/WarningTest.xml index a6bfeefd..cedb9a9f 100644 --- a/test/fixtures/common_results/junit/WarningTest.xml +++ b/test/fixtures/common_results/junit/WarningTest.xml @@ -1,5 +1,5 @@ - + diff --git a/test/fixtures/special_chars/data-provider-with-special-chars.xml b/test/fixtures/special_chars/data-provider-with-special-chars.xml index df5799db..a85a29c8 100644 --- a/test/fixtures/special_chars/data-provider-with-special-chars.xml +++ b/test/fixtures/special_chars/data-provider-with-special-chars.xml @@ -1,5 +1,5 @@ - + From 9c34baa8b47f3dd874e3811a089b9d2c58081572 Mon Sep 17 00:00:00 2001 From: Torben Evald Hansen Date: Wed, 4 Sep 2024 23:15:27 +0200 Subject: [PATCH 5/7] Update PHPUnit and add failOnPhpunitDeprecation option (#883) --- src/WrapperRunner/WrapperRunner.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WrapperRunner/WrapperRunner.php b/src/WrapperRunner/WrapperRunner.php index f6fc5008..20640bf8 100644 --- a/src/WrapperRunner/WrapperRunner.php +++ b/src/WrapperRunner/WrapperRunner.php @@ -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(), From 9b772869372508e967133a61614287c95ac13daa Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 9 Sep 2024 12:20:44 +0200 Subject: [PATCH 6/7] Update PHPUnit compatibility to 10.5.33 --- composer.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 697378a2..2288b45e 100644 --- a/composer.json +++ b/composer.json @@ -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": { From 02a3246a611b935bbe8650d644a1d24b2d173713 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 9 Sep 2024 12:35:37 +0200 Subject: [PATCH 7/7] Build fixes --- phpstan-baseline.neon | 10 ---------- .../ApplicationForWrapperWorker.php | 20 ++++++------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3f9532b6..1e4d90a3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/src/WrapperRunner/ApplicationForWrapperWorker.php b/src/WrapperRunner/ApplicationForWrapperWorker.php index 7748f03b..f678ce99 100644 --- a/src/WrapperRunner/ApplicationForWrapperWorker.php +++ b/src/WrapperRunner/ApplicationForWrapperWorker.php @@ -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; @@ -41,7 +40,6 @@ use function str_ends_with; use function strpos; use function substr; -use function version_compare; /** * @internal @@ -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); } @@ -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); @@ -234,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(), ); }