Skip to content

Commit 3487ca1

Browse files
authored
Merge pull request #431 from Roave/fix/#429-ensure-internal-source-locator-considered-before-vendor-polyfills
#429 polyfills should not override reflected internal PHP symbols
2 parents 050cf1e + 842b835 commit 3487ca1

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

src/LocateDependencies/LocateDependenciesViaComposer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function __invoke(string $installationPath, bool $includeDevelopmentDepen
5656
}, $installationPath);
5757

5858
return new AggregateSourceLocator([
59-
(new MakeLocatorForInstalledJson())($installationPath, $this->astLocator),
6059
new PhpInternalSourceLocator($this->astLocator, new ReflectionSourceStubber()),
60+
(new MakeLocatorForInstalledJson())($installationPath, $this->astLocator),
6161
]);
6262
}
6363

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"description": "a package"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
interface Stringable
4+
{
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"name": "a/b",
4+
"autoload": {
5+
"files": [
6+
"stringable-polyfill.php"
7+
]
8+
}
9+
}
10+
]

test/unit/LocateDependencies/LocateDependenciesViaComposerTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use ReflectionProperty;
1515
use Roave\BackwardCompatibility\LocateDependencies\LocateDependenciesViaComposer;
1616
use Roave\BetterReflection\BetterReflection;
17+
use Roave\BetterReflection\Reflector\DefaultReflector;
1718
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
1819
use Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator;
1920
use Roave\BetterReflection\SourceLocator\Type\SourceLocator;
@@ -116,7 +117,20 @@ public function testWillLocateDependencies(): void
116117
])->coerce($reflectionLocators->getValue($locator));
117118

118119
self::assertCount(2, $locators);
119-
self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[1]);
120+
self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[0]);
121+
}
122+
123+
public function testInternalReflectionStubsTakePriorityOverInstalledPolyfills(): void
124+
{
125+
$this->expectedInstallationPath = Type\string()
126+
->assert(Filesystem\canonicalize(__DIR__ . '/../../asset/composer-installation-with-vendor-overriding-internal-sources'));
127+
128+
$reflector = new DefaultReflector(($this->locateDependencies)($this->expectedInstallationPath, false));
129+
130+
self::assertTrue(
131+
$reflector->reflectClass('Stringable')
132+
->isInternal()
133+
);
120134
}
121135

122136
public function testDevelopmentDependenciesCanBeOptionallyInstalled(): void
@@ -166,6 +180,6 @@ public function testDevelopmentDependenciesCanBeOptionallyInstalled(): void
166180
])->coerce($reflectionLocators->getValue($locator));
167181

168182
self::assertCount(2, $locators);
169-
self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[1]);
183+
self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[0]);
170184
}
171185
}

0 commit comments

Comments
 (0)