Skip to content

Commit fd568ea

Browse files
Merge branch '10.5' into 11.0
2 parents feb50cf + 3299d8c commit fd568ea

File tree

10 files changed

+31
-38
lines changed

10 files changed

+31
-38
lines changed

.psalm/baseline.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,6 @@
730730
<code><![CDATA[listTestsXml]]></code>
731731
<code><![CDATA[logEventsText]]></code>
732732
<code><![CDATA[logEventsText]]></code>
733-
<code><![CDATA[logEventsText]]></code>
734-
<code><![CDATA[logEventsVerboseText]]></code>
735733
<code><![CDATA[logEventsVerboseText]]></code>
736734
<code><![CDATA[logEventsVerboseText]]></code>
737735
<code><![CDATA[logfileJunit]]></code>

src/Framework/TestSuite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function addTestSuite(ReflectionClass $testClass, array $groups = []): vo
224224
*/
225225
public function addTestFile(string $filename, array $groups = []): void
226226
{
227-
if (is_file($filename) && str_ends_with($filename, '.phpt')) {
227+
if (str_ends_with($filename, '.phpt') && is_file($filename)) {
228228
try {
229229
$this->addTest(new PhptTestCase($filename));
230230
} catch (RunnerException $e) {

src/Runner/Baseline/Issue.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,13 @@ public function equals(self $other): bool
123123
*/
124124
private static function calculateHash(string $file, int $line): string
125125
{
126-
if (!is_file($file)) {
126+
$lines = @file($file, FILE_IGNORE_NEW_LINES);
127+
128+
if ($lines === false && !is_file($file)) {
127129
throw new FileDoesNotExistException($file);
128130
}
129131

130-
$lines = file($file, FILE_IGNORE_NEW_LINES);
131-
$key = $line - 1;
132+
$key = $line - 1;
132133

133134
if (!isset($lines[$key])) {
134135
throw new FileDoesNotHaveLineException($file, $line);

src/Runner/PhptTestCase.php

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

641-
if (is_file($files['coverage'])) {
642-
$buffer = @file_get_contents($files['coverage']);
641+
$buffer = @file_get_contents($files['coverage']);
643642

644-
if ($buffer !== false) {
645-
$coverage = @unserialize($buffer);
643+
if ($buffer !== false) {
644+
$coverage = @unserialize($buffer);
646645

647-
if ($coverage === false) {
648-
$coverage = RawCodeCoverageData::fromXdebugWithoutPathCoverage([]);
649-
}
646+
if ($coverage === false) {
647+
$coverage = RawCodeCoverageData::fromXdebugWithoutPathCoverage([]);
650648
}
651649
}
652650

src/Runner/ResultCache/DefaultResultCache.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use function file_put_contents;
1818
use function is_array;
1919
use function is_dir;
20-
use function is_file;
2120
use function json_decode;
2221
use function json_encode;
2322
use PHPUnit\Framework\TestStatus\TestStatus;
@@ -86,12 +85,14 @@ public function time(string $id): float
8685

8786
public function load(): void
8887
{
89-
if (!is_file($this->cacheFilename)) {
88+
$contents = @file_get_contents($this->cacheFilename);
89+
90+
if ($contents === false) {
9091
return;
9192
}
9293

9394
$data = json_decode(
94-
file_get_contents($this->cacheFilename),
95+
$contents,
9596
true,
9697
);
9798

src/TextUI/Application.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace PHPUnit\TextUI;
1111

1212
use const PHP_EOL;
13-
use function is_file;
1413
use function is_readable;
1514
use function printf;
1615
use function realpath;
@@ -510,9 +509,7 @@ private function writeRandomSeedInformation(Printer $printer, Configuration $con
510509
private function registerLogfileWriters(Configuration $configuration): void
511510
{
512511
if ($configuration->hasLogEventsText()) {
513-
if (is_file($configuration->logEventsText())) {
514-
unlink($configuration->logEventsText());
515-
}
512+
@unlink($configuration->logEventsText());
516513

517514
EventFacade::instance()->registerTracer(
518515
new EventLogger(
@@ -523,9 +520,7 @@ private function registerLogfileWriters(Configuration $configuration): void
523520
}
524521

525522
if ($configuration->hasLogEventsVerboseText()) {
526-
if (is_file($configuration->logEventsVerboseText())) {
527-
unlink($configuration->logEventsVerboseText());
528-
}
523+
@unlink($configuration->logEventsVerboseText());
529524

530525
EventFacade::instance()->registerTracer(
531526
new EventLogger(

src/TextUI/Configuration/Cli/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public function fromParameters(array $parameters): Configuration
394394
case '--use-baseline':
395395
$useBaseline = $option[1];
396396

397-
if (!is_file($useBaseline) && basename($useBaseline) === $useBaseline) {
397+
if (basename($useBaseline) === $useBaseline && !is_file($useBaseline)) {
398398
$useBaseline = getcwd() . DIRECTORY_SEPARATOR . $useBaseline;
399399
}
400400

src/TextUI/Configuration/TestSuiteBuilder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ public function build(Configuration $configuration): TestSuite
9191
*/
9292
private function testSuiteFromPath(string $path, array $suffixes, ?TestSuite $suite = null): TestSuite
9393
{
94+
if (str_ends_with($path, '.phpt') && is_file($path)) {
95+
$suite = $suite ?: TestSuite::empty($path);
96+
$suite->addTestFile($path);
97+
98+
return $suite;
99+
}
100+
94101
if (is_dir($path)) {
95102
$files = (new FileIteratorFacade)->getFilesAsArray($path, $suffixes);
96103

@@ -100,13 +107,6 @@ private function testSuiteFromPath(string $path, array $suffixes, ?TestSuite $su
100107
return $suite;
101108
}
102109

103-
if (is_file($path) && str_ends_with($path, '.phpt')) {
104-
$suite = $suite ?: TestSuite::empty($path);
105-
$suite->addTestFile($path);
106-
107-
return $suite;
108-
}
109-
110110
try {
111111
$testClass = (new TestSuiteLoader)->load($path);
112112
} catch (Exception $e) {

src/Util/Filter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ private static function shouldPrintFrame(array $frame, false|string $prefix, Exc
8989
$script = '';
9090
}
9191

92-
return is_file($file) &&
92+
return $fileIsNotPrefixed &&
93+
$file !== $script &&
9394
self::fileIsExcluded($file, $excludeList) &&
94-
$fileIsNotPrefixed &&
95-
$file !== $script;
95+
is_file($file);
9696
}
9797

9898
private static function fileIsExcluded(string $file, ExcludeList $excludeList): bool

src/Util/PHP/AbstractPhpProcess.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use function array_merge;
1515
use function assert;
1616
use function escapeshellarg;
17-
use function file_exists;
1817
use function file_get_contents;
1918
use function ini_get_all;
2019
use function restore_error_handler;
@@ -137,12 +136,13 @@ public function runTestJob(string $job, Test $test, string $processResultFile):
137136
{
138137
$_result = $this->runJob($job);
139138

140-
$processResult = '';
139+
$processResult = @file_get_contents($processResultFile);
141140

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

145143
@unlink($processResultFile);
144+
} else {
145+
$processResult = '';
146146
}
147147

148148
$this->processChildResult(

0 commit comments

Comments
 (0)