Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FileLoader.php fatal error when loading a non existing file #3508

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Util/FileLoader.php
Expand Up @@ -31,10 +31,19 @@ public static function checkAndLoad(string $filename): string
$includePathFilename = \stream_resolve_include_path($filename);
$localFile = __DIR__ . \DIRECTORY_SEPARATOR . $filename;

/**
* @see https://github.com/sebastianbergmann/phpunit/pull/2751
/*
* Due to strict_types = 1 declaration, fopen() expects a string as the path parameter.
* If a boolean is provided as the path paramater, then a fatal TypeError is thrown, without
* describing what file has failed to load.
*/
$isReadable = @\fopen($includePathFilename, 'r') !== false;
if ($includePathFilename !== false) {
/**
* @see https://github.com/sebastianbergmann/phpunit/pull/2751
*/
$isReadable = @\fopen($includePathFilename, 'r') !== false;
} else {
$isReadable = false;
}

if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) {
throw new Exception(
Expand Down