Skip to content

Commit

Permalink
Merge pull request #431 from Roave/fix/#429-ensure-internal-source-lo…
Browse files Browse the repository at this point in the history
…cator-considered-before-vendor-polyfills

#429 polyfills should not override reflected internal PHP symbols
  • Loading branch information
Ocramius authored Feb 4, 2022
2 parents 050cf1e + 842b835 commit 3487ca1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/LocateDependencies/LocateDependenciesViaComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"description": "a package"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

interface Stringable
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"name": "a/b",
"autoload": {
"files": [
"stringable-polyfill.php"
]
}
}
]
18 changes: 16 additions & 2 deletions test/unit/LocateDependencies/LocateDependenciesViaComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ReflectionProperty;
use Roave\BackwardCompatibility\LocateDependencies\LocateDependenciesViaComposer;
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflector\DefaultReflector;
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
use Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator;
use Roave\BetterReflection\SourceLocator\Type\SourceLocator;
Expand Down Expand Up @@ -116,7 +117,20 @@ public function testWillLocateDependencies(): void
])->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
Expand Down Expand Up @@ -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]);
}
}

0 comments on commit 3487ca1

Please sign in to comment.