Skip to content

Commit

Permalink
Added 5764 regression test
Browse files Browse the repository at this point in the history
revert parts of #5742
  • Loading branch information
staabm committed Mar 21, 2024
1 parent 4cf8824 commit 93025fe
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/Runner/PhptTestCase.php
Expand Up @@ -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']);

Check warning on line 643 in src/Runner/PhptTestCase.php

View check run for this annotation

Codecov / codecov/patch

src/Runner/PhptTestCase.php#L641-L643

Added lines #L641 - L643 were not covered by tests
}

if ($buffer !== false) {
$coverage = @unserialize($buffer);
Expand Down
5 changes: 4 additions & 1 deletion src/Runner/ResultCache/DefaultResultCache.php
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/TextUI/Application.php
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions src/Util/PHP/AbstractPhpProcess.php
Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions tests/end-to-end/regression/5764/5764.phpt
@@ -0,0 +1,21 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5764
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--configuration';
$_SERVER['argv'][] = __DIR__ . '/';

require_once __DIR__ . '/../../../bootstrap.php';
(new PHPUnit\TextUI\Application)->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!
7 changes: 7 additions & 0 deletions tests/end-to-end/regression/5764/error-handler.php
@@ -0,0 +1,7 @@
<?php

// be forgiving with error handlers which do not suppress `@` prefixed lines
set_error_handler(function(int $err_lvl, string $err_msg, string $err_file, int $err_line): bool {
throw new \ErrorException($err_msg, 0, $err_lvl, $err_file, $err_line);
});

11 changes: 11 additions & 0 deletions tests/end-to-end/regression/5764/phpunit.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../phpunit.xsd"
bootstrap="error-handler.php"
>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
17 changes: 17 additions & 0 deletions tests/end-to-end/regression/5764/tests/Issue5764Test.php
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
{
}

0 comments on commit 93025fe

Please sign in to comment.