diff --git a/src/LocateDependencies/LocateDependenciesViaComposer.php b/src/LocateDependencies/LocateDependenciesViaComposer.php index e913d4ed..2ab1f3c1 100644 --- a/src/LocateDependencies/LocateDependenciesViaComposer.php +++ b/src/LocateDependencies/LocateDependenciesViaComposer.php @@ -56,8 +56,8 @@ public function __invoke(string $installationPath, bool $includeDevelopmentDepen }, $installationPath); return new AggregateSourceLocator([ - (new MakeLocatorForInstalledJson())($installationPath, $this->astLocator), new PhpInternalSourceLocator($this->astLocator, new ReflectionSourceStubber()), + (new MakeLocatorForInstalledJson())($installationPath, $this->astLocator), ]); } diff --git a/test/asset/composer-installation-with-vendor-overriding-internal-sources/composer.json b/test/asset/composer-installation-with-vendor-overriding-internal-sources/composer.json new file mode 100644 index 00000000..c95f1dd3 --- /dev/null +++ b/test/asset/composer-installation-with-vendor-overriding-internal-sources/composer.json @@ -0,0 +1,3 @@ +{ + "description": "a package" +} diff --git a/test/asset/composer-installation-with-vendor-overriding-internal-sources/vendor/a/b/stringable-polyfill.php b/test/asset/composer-installation-with-vendor-overriding-internal-sources/vendor/a/b/stringable-polyfill.php new file mode 100644 index 00000000..81e1c5d5 --- /dev/null +++ b/test/asset/composer-installation-with-vendor-overriding-internal-sources/vendor/a/b/stringable-polyfill.php @@ -0,0 +1,5 @@ +coerce($reflectionLocators->getValue($locator)); self::assertCount(2, $locators); - self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[1]); + self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[0]); + } + + public function testInternalReflectionStubsTakePriorityOverInstalledPolyfills(): void + { + $this->expectedInstallationPath = Type\string() + ->assert(Filesystem\canonicalize(__DIR__ . '/../../asset/composer-installation-with-vendor-overriding-internal-sources')); + + $reflector = new DefaultReflector(($this->locateDependencies)($this->expectedInstallationPath, false)); + + self::assertTrue( + $reflector->reflectClass('Stringable') + ->isInternal() + ); } public function testDevelopmentDependenciesCanBeOptionallyInstalled(): void @@ -166,6 +180,6 @@ public function testDevelopmentDependenciesCanBeOptionallyInstalled(): void ])->coerce($reflectionLocators->getValue($locator)); self::assertCount(2, $locators); - self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[1]); + self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[0]); } }