From 3b58e655e0306060af0a554668e449b5c88326e0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 21 Mar 2024 17:00:12 +0100 Subject: [PATCH] Added 5764 regression test revert parts of https://github.com/sebastianbergmann/phpunit/pull/5742 --- src/Runner/PhptTestCase.php | 5 ++++- src/Runner/ResultCache/DefaultResultCache.php | 5 ++++- src/TextUI/Application.php | 8 +++++-- src/Util/PHP/AbstractPhpProcess.php | 8 +++---- tests/end-to-end/regression/5764/5764.phpt | 21 +++++++++++++++++++ .../regression/5764/error-handler.php | 7 +++++++ tests/end-to-end/regression/5764/phpunit.xml | 11 ++++++++++ .../regression/5764/tests/Issue5764Test.php | 17 +++++++++++++++ 8 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 tests/end-to-end/regression/5764/5764.phpt create mode 100644 tests/end-to-end/regression/5764/error-handler.php create mode 100644 tests/end-to-end/regression/5764/phpunit.xml create mode 100644 tests/end-to-end/regression/5764/tests/Issue5764Test.php diff --git a/src/Runner/PhptTestCase.php b/src/Runner/PhptTestCase.php index a5840f052b0..690c5ce8020 100644 --- a/src/Runner/PhptTestCase.php +++ b/src/Runner/PhptTestCase.php @@ -638,7 +638,10 @@ private function cleanupForCoverage(): RawCodeCoverageData $coverage = RawCodeCoverageData::fromXdebugWithoutPathCoverage([]); $files = $this->getCoverageFiles(); - $buffer = @file_get_contents($files['coverage']); + $buffer = false; + if (is_file($files['coverage'])) { + $buffer = @file_get_contents($files['coverage']); + } if ($buffer !== false) { $coverage = @unserialize($buffer); diff --git a/src/Runner/ResultCache/DefaultResultCache.php b/src/Runner/ResultCache/DefaultResultCache.php index 090935f98f9..b955c601132 100644 --- a/src/Runner/ResultCache/DefaultResultCache.php +++ b/src/Runner/ResultCache/DefaultResultCache.php @@ -85,7 +85,10 @@ public function time(string $id): float public function load(): void { - $contents = @file_get_contents($this->cacheFilename); + if (!is_file($this->cacheFilename)) { + return; + } + $contents = file_get_contents($this->cacheFilename); if ($contents === false) { return; diff --git a/src/TextUI/Application.php b/src/TextUI/Application.php index 6fbca1f58c6..a8cd3c450db 100644 --- a/src/TextUI/Application.php +++ b/src/TextUI/Application.php @@ -516,7 +516,9 @@ private function writeRandomSeedInformation(Printer $printer, Configuration $con private function registerLogfileWriters(Configuration $configuration): void { if ($configuration->hasLogEventsText()) { - @unlink($configuration->logEventsText()); + if (is_file($configuration->logEventsText())) { + unlink($configuration->logEventsText()); + } EventFacade::instance()->registerTracer( new EventLogger( @@ -527,7 +529,9 @@ private function registerLogfileWriters(Configuration $configuration): void } if ($configuration->hasLogEventsVerboseText()) { - @unlink($configuration->logEventsVerboseText()); + if (is_file($configuration->logEventsVerboseText())) { + unlink($configuration->logEventsVerboseText()); + } EventFacade::instance()->registerTracer( new EventLogger( diff --git a/src/Util/PHP/AbstractPhpProcess.php b/src/Util/PHP/AbstractPhpProcess.php index 6a9b636afe4..1f3600d4511 100644 --- a/src/Util/PHP/AbstractPhpProcess.php +++ b/src/Util/PHP/AbstractPhpProcess.php @@ -138,13 +138,11 @@ public function runTestJob(string $job, Test $test, string $processResultFile): { $_result = $this->runJob($job); - $processResult = @file_get_contents($processResultFile); - - if ($processResult !== false) { + $processResult = ''; + if (file_exists($processResultFile)) { + $processResult = file_get_contents($processResultFile); @unlink($processResultFile); - } else { - $processResult = ''; } $this->processChildResult( diff --git a/tests/end-to-end/regression/5764/5764.phpt b/tests/end-to-end/regression/5764/5764.phpt new file mode 100644 index 00000000000..5c56917a27e --- /dev/null +++ b/tests/end-to-end/regression/5764/5764.phpt @@ -0,0 +1,21 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/5764 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s +Configuration: %s + +There was 1 PHPUnit test runner warning: + +1) No tests found in class "PHPUnit\TestFixture\Issue5764\Issue5764Test". + +No tests executed! diff --git a/tests/end-to-end/regression/5764/error-handler.php b/tests/end-to-end/regression/5764/error-handler.php new file mode 100644 index 00000000000..0cd6a2a8a53 --- /dev/null +++ b/tests/end-to-end/regression/5764/error-handler.php @@ -0,0 +1,7 @@ + + + + + tests + + + diff --git a/tests/end-to-end/regression/5764/tests/Issue5764Test.php b/tests/end-to-end/regression/5764/tests/Issue5764Test.php new file mode 100644 index 00000000000..9093ba2adbb --- /dev/null +++ b/tests/end-to-end/regression/5764/tests/Issue5764Test.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture\Issue5764; + +use Exception; +use PHPUnit\Framework\TestCase; + +final class Issue5764Test extends TestCase +{ +}