From b04ac1d106403874318dc897caec9b0906e983a7 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 4 Feb 2019 06:21:54 +0100 Subject: [PATCH] Closes #3508 --- ChangeLog-8.0.md | 7 +++++++ src/Util/FileLoader.php | 22 ++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ChangeLog-8.0.md b/ChangeLog-8.0.md index 957f6f79806..e2dd435c2cc 100644 --- a/ChangeLog-8.0.md +++ b/ChangeLog-8.0.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 8.0 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [8.0.2] - 2019-MM-DD + +### Fixed + +* Fixed [#3508](https://github.com/sebastianbergmann/phpunit/pull/3508): `TypeError` in `Fileloader` when trying to load nonexistent file + ## [8.0.1] - 2019-02-03 ### Fixed @@ -37,6 +43,7 @@ All notable changes of the PHPUnit 8.0 release series are documented in this fil * Implemented [#2762](https://github.com/sebastianbergmann/phpunit/issues/2762): Drop support for PHP 7.1 * Implemented [#3123](https://github.com/sebastianbergmann/phpunit/issues/3123): Remove `PHPUnit_Framework_MockObject_MockObject` +[8.0.2]: https://github.com/sebastianbergmann/phpunit/compare/8.0.1...8.0.2 [8.0.1]: https://github.com/sebastianbergmann/phpunit/compare/8.0.0...8.0.1 [8.0.0]: https://github.com/sebastianbergmann/phpunit/compare/7.5...8.0.0 diff --git a/src/Util/FileLoader.php b/src/Util/FileLoader.php index 817ee70d699..de3255442ab 100644 --- a/src/Util/FileLoader.php +++ b/src/Util/FileLoader.php @@ -29,14 +29,16 @@ final class FileLoader 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 - */ - $isReadable = @\fopen($includePathFilename, 'r') !== false; + if (!$includePathFilename) { + throw new Exception( + \sprintf('Cannot open file "%s".' . "\n", $filename) + ); + } + + $localFile = __DIR__ . \DIRECTORY_SEPARATOR . $filename; - if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) { + if (!self::isReadable($includePathFilename) || $includePathFilename === $localFile) { throw new Exception( \sprintf('Cannot open file "%s".' . "\n", $filename) ); @@ -65,4 +67,12 @@ public static function load(string $filename): void } } } + + /** + * @see https://github.com/sebastianbergmann/phpunit/pull/2751 + */ + private static function isReadable(string $filename): bool + { + return @\fopen($filename, 'r') !== false; + } }