Skip to content

Commit

Permalink
Closes #4573
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 27, 2021
1 parent c6f02fe commit 9b42ef9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChangeLog-9.5.md
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions src/Util/Filter.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 9b42ef9

Please sign in to comment.