From 9b42ef9586ccb943c8978dc0757c482fc7ef60ba Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 27 Jan 2021 08:29:45 +0100 Subject: [PATCH] Closes #4573 --- ChangeLog-9.5.md | 1 + src/Util/Filter.php | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ChangeLog-9.5.md b/ChangeLog-9.5.md index e74ecd072b9..0a137c7a4ec 100644 --- a/ChangeLog-9.5.md +++ b/ChangeLog-9.5.md @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 9.5 release series are documented in this fil ### Fixed +* [#4573](https://github.com/sebastianbergmann/phpunit/issues/4573): No stack trace printed when PHPUnit is used from PHAR * [#4590](https://github.com/sebastianbergmann/phpunit/issues/4590): `--coverage-text` CLI option is documented wrong ## [9.5.1] - 2021-01-17 diff --git a/src/Util/Filter.php b/src/Util/Filter.php index c7363443f41..42563937d75 100644 --- a/src/Util/Filter.php +++ b/src/Util/Filter.php @@ -15,6 +15,7 @@ use function is_file; use function realpath; use function sprintf; +use function strpos; use PHPUnit\Framework\Exception; use PHPUnit\Framework\SyntheticError; use Throwable; @@ -56,7 +57,7 @@ public static function getFilteredStacktrace(Throwable $t): string ); } - $prefix = defined('__PHPUNIT_PHAR_ROOT__') ? __PHPUNIT_PHAR_ROOT__ : null; + $prefix = defined('__PHPUNIT_PHAR_ROOT__') ? __PHPUNIT_PHAR_ROOT__ : false; $excludeList = new ExcludeList; foreach ($eTrace as $frame) { @@ -72,28 +73,26 @@ public static function getFilteredStacktrace(Throwable $t): string return $filteredStacktrace; } - private static function shouldPrintFrame(array $frame, ?string $prefix, ExcludeList $excludeList): bool + private static function shouldPrintFrame(array $frame, $prefix, ExcludeList $excludeList): bool { if (!isset($frame['file'])) { return false; } - // @see https://github.com/sebastianbergmann/phpunit/issues/4033 - $script = ''; + $file = $frame['file']; + $fileIsNotPrefixed = $prefix === false || strpos($file, $prefix) !== 0; + // @see https://github.com/sebastianbergmann/phpunit/issues/4033 if (isset($GLOBALS['_SERVER']['SCRIPT_NAME'])) { $script = realpath($GLOBALS['_SERVER']['SCRIPT_NAME']); + } else { + $script = ''; } - $file = $frame['file']; - - if ($file === $script) { - return false; - } - - return $prefix === null && + return is_file($file) && self::fileIsExcluded($file, $excludeList) && - is_file($file); + $fileIsNotPrefixed && + $file !== $script; } private static function fileIsExcluded(string $file, ExcludeList $excludeList): bool