phpunit
phpunit copied to clipboard
ExcludeList::addDirectory won’t initialize correctly, assert tracebacks will show PHPUnit classes
Q | A |
---|---|
PHPUnit version | 9.5.10 |
PHP version | 8.1.2 |
Installation Method | Composer |
Summary
PHPUnit\Util\ExcludeList
won’t initialize correctly when static addDirectory
is called before a class instance was created.
This interface is required to create new custom asserts without showing internals in the stacktrace. As introduced and described in #4186
Current behavior
PHPUnit\Util\ExcludeList::addDirectory
won’t initialize ExcludeList ::$directories
correctly.
All Tracebacks show PHPUnit classes after using this interface
How to reproduce
PHPUnit\Util\ExcludeList::addDirectory(__DIR__);
Failing assert shows a long stacktrace with files in /vendor/phpunit/phpunit/src/
Workaround:
$excludeList = new \PHPUnit\Util\ExcludeList();
if (!$excludeList->isExcluded(__FILE__)) {
// Add directory after initialize ExcludeList::$directories via isExcluded
\PHPUnit\Util\ExcludeList::addDirectory(__DIR__);
}
Expected behavior
PHPUnit\Util\ExcludeList::addDirectory($directory);
should be in the compatibility promise and ExcludeList will initialize itself properly, Later tracebacks won’t show PHPUnit internal files and user added directories.
As the backward compatibility promise isn’t clear, please provide a stable interface.
(As there isn't a static function to check the directories, it would be nice if a directory won't be added as duplicate to the internal list)