Skip to content

Commit 3b58e65

Browse files
staabmsebastianbergmann
authored andcommitted
Added 5764 regression test
revert parts of #5742
1 parent 4cf8824 commit 3b58e65

File tree

8 files changed

+73
-9
lines changed

8 files changed

+73
-9
lines changed

src/Runner/PhptTestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,10 @@ private function cleanupForCoverage(): RawCodeCoverageData
638638
$coverage = RawCodeCoverageData::fromXdebugWithoutPathCoverage([]);
639639
$files = $this->getCoverageFiles();
640640

641-
$buffer = @file_get_contents($files['coverage']);
641+
$buffer = false;
642+
if (is_file($files['coverage'])) {
643+
$buffer = @file_get_contents($files['coverage']);
644+
}
642645

643646
if ($buffer !== false) {
644647
$coverage = @unserialize($buffer);

src/Runner/ResultCache/DefaultResultCache.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public function time(string $id): float
8585

8686
public function load(): void
8787
{
88-
$contents = @file_get_contents($this->cacheFilename);
88+
if (!is_file($this->cacheFilename)) {
89+
return;
90+
}
91+
$contents = file_get_contents($this->cacheFilename);
8992

9093
if ($contents === false) {
9194
return;

src/TextUI/Application.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ private function writeRandomSeedInformation(Printer $printer, Configuration $con
516516
private function registerLogfileWriters(Configuration $configuration): void
517517
{
518518
if ($configuration->hasLogEventsText()) {
519-
@unlink($configuration->logEventsText());
519+
if (is_file($configuration->logEventsText())) {
520+
unlink($configuration->logEventsText());
521+
}
520522

521523
EventFacade::instance()->registerTracer(
522524
new EventLogger(
@@ -527,7 +529,9 @@ private function registerLogfileWriters(Configuration $configuration): void
527529
}
528530

529531
if ($configuration->hasLogEventsVerboseText()) {
530-
@unlink($configuration->logEventsVerboseText());
532+
if (is_file($configuration->logEventsVerboseText())) {
533+
unlink($configuration->logEventsVerboseText());
534+
}
531535

532536
EventFacade::instance()->registerTracer(
533537
new EventLogger(

src/Util/PHP/AbstractPhpProcess.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ public function runTestJob(string $job, Test $test, string $processResultFile):
138138
{
139139
$_result = $this->runJob($job);
140140

141-
$processResult = @file_get_contents($processResultFile);
142-
143-
if ($processResult !== false) {
141+
$processResult = '';
144142

143+
if (file_exists($processResultFile)) {
144+
$processResult = file_get_contents($processResultFile);
145145
@unlink($processResultFile);
146-
} else {
147-
$processResult = '';
148146
}
149147

150148
$this->processChildResult(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/5764
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/';
8+
9+
require_once __DIR__ . '/../../../bootstrap.php';
10+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
11+
--EXPECTF--
12+
PHPUnit %s by Sebastian Bergmann and contributors.
13+
14+
Runtime: %s
15+
Configuration: %s
16+
17+
There was 1 PHPUnit test runner warning:
18+
19+
1) No tests found in class "PHPUnit\TestFixture\Issue5764\Issue5764Test".
20+
21+
No tests executed!
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// be forgiving with error handlers which do not suppress `@` prefixed lines
4+
set_error_handler(function(int $err_lvl, string $err_msg, string $err_file, int $err_line): bool {
5+
throw new \ErrorException($err_msg, 0, $err_lvl, $err_file, $err_line);
6+
});
7+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../phpunit.xsd"
4+
bootstrap="error-handler.php"
5+
>
6+
<testsuites>
7+
<testsuite name="default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
</phpunit>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue5764;
11+
12+
use Exception;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class Issue5764Test extends TestCase
16+
{
17+
}

0 commit comments

Comments
 (0)