Skip to content

Commit df17592

Browse files
committed
Fix TestCaseSourceLocatorFactory
1 parent 9018681 commit df17592

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Testing/TestCaseSourceLocatorFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator;
1717
use PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker;
1818
use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher;
19+
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository;
1920
use PHPStan\Reflection\BetterReflection\SourceLocator\PhpVersionBlacklistSourceLocator;
2021
use ReflectionClass;
2122
use function dirname;
@@ -35,6 +36,7 @@ final class TestCaseSourceLocatorFactory
3536
*/
3637
public function __construct(
3738
private ComposerJsonAndInstalledJsonSourceLocatorMaker $composerJsonAndInstalledJsonSourceLocatorMaker,
39+
private OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
3840
private Parser $phpParser,
3941
private Parser $php8Parser,
4042
private FileNodesFetcher $fileNodesFetcher,
@@ -57,7 +59,13 @@ public function create(): SourceLocator
5759
$this->excludePaths,
5860
]));
5961
if ($classLoaderReflection->hasProperty('vendorDir') && ! isset(self::$composerSourceLocatorsCache[$cacheKey])) {
60-
$composerLocators = [];
62+
$composerLocators = [
63+
$this->optimizedSingleFileSourceLocatorRepository->getOrCreate(
64+
PHP_VERSION_ID < 80500
65+
? __DIR__ . '/../../stubs/runtime/Attribute84.php'
66+
: __DIR__ . '/../../stubs/runtime/Attribute85.php',
67+
),
68+
];
6169
$vendorDirProperty = $classLoaderReflection->getProperty('vendorDir');
6270
$vendorDirProperty->setAccessible(true);
6371
foreach ($classLoaders as $classLoader) {

0 commit comments

Comments
 (0)