Skip to content

Commit

Permalink
Closes #5022
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 13, 2022
1 parent c0fc826 commit 597bfd0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
8 changes: 0 additions & 8 deletions .psalm/baseline.xml
Expand Up @@ -1294,9 +1294,6 @@
</MissingReturnType>
</file>
<file src="src/Util/ExcludeList.php">
<DocblockTypeContradiction occurrences="1">
<code>self::$directories === null</code>
</DocblockTypeContradiction>
<MissingThrowsDocblock occurrences="1"/>
</file>
<file src="src/Util/Filter.php">
Expand Down Expand Up @@ -1430,11 +1427,6 @@
<code>$stream</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Util/Reflection.php">
<PossiblyNullArgument occurrences="1">
<code>$filter</code>
</PossiblyNullArgument>
</file>
<file src="src/Util/Test.php">
<MissingReturnType occurrences="1">
<code>sanitizeVersionNumber</code>
Expand Down
1 change: 1 addition & 0 deletions ChangeLog-9.5.md
Expand Up @@ -8,6 +8,7 @@ All notable changes of the PHPUnit 9.5 release series are documented in this fil

* [#5015](https://github.com/sebastianbergmann/phpunit/pull/5015): Ukraine banner unreadable on black background
* [#5020](https://github.com/sebastianbergmann/phpunit/issues/5020): PHPUnit 9 breaks loading of PSR-0/PEAR style classes
* [#5022](https://github.com/sebastianbergmann/phpunit/issues/5022): `ExcludeList::addDirectory()` does not work correctly

## [9.5.21] - 2022-06-19

Expand Down
69 changes: 38 additions & 31 deletions src/Util/ExcludeList.php
Expand Up @@ -166,7 +166,12 @@ final class ExcludeList
/**
* @var string[]
*/
private static $directories;
private static $directories = [];

/**
* @var bool
*/
private static $initialized = false;

public static function addDirectory(string $directory): void
{
Expand Down Expand Up @@ -219,39 +224,41 @@ public function isExcluded(string $file): bool
*/
private function initialize(): void
{
if (self::$directories === null) {
self::$directories = [];

foreach (self::EXCLUDED_CLASS_NAMES as $className => $parent) {
if (!class_exists($className)) {
continue;
}

try {
$directory = (new ReflectionClass($className))->getFileName();
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
(int) $e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd

for ($i = 0; $i < $parent; $i++) {
$directory = dirname($directory);
}

self::$directories[] = $directory;
if (self::$initialized) {
return;
}

foreach (self::EXCLUDED_CLASS_NAMES as $className => $parent) {
if (!class_exists($className)) {
continue;
}

// Hide process isolation workaround on Windows.
if (DIRECTORY_SEPARATOR === '\\') {
// tempnam() prefix is limited to first 3 chars.
// @see https://php.net/manual/en/function.tempnam.php
self::$directories[] = sys_get_temp_dir() . '\\PHP';
try {
$directory = (new ReflectionClass($className))->getFileName();
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
(int) $e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd

for ($i = 0; $i < $parent; $i++) {
$directory = dirname($directory);
}

self::$directories[] = $directory;
}

// Hide process isolation workaround on Windows.
if (DIRECTORY_SEPARATOR === '\\') {
// tempnam() prefix is limited to first 3 chars.
// @see https://php.net/manual/en/function.tempnam.php
self::$directories[] = sys_get_temp_dir() . '\\PHP';
}

self::$initialized = true;
}
}

0 comments on commit 597bfd0

Please sign in to comment.