8000 bug #58859 [AssetMapper] ignore missing directory in `isVendor()` (al… · symfony/symfony@10be4d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10be4d6

Browse files
bug #58859 [AssetMapper] ignore missing directory in isVendor() (alexislefebvre)
This PR was merged into the 6.4 branch. Discussion ---------- [AssetMapper] ignore missing directory in `isVendor()` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #58858 | License | MIT ~~I don't know how to add tests yet, because this method is private.~~ Commits ------- 9e3984f fix: ignore missing directory in isVendor()
2 parents cfb39c5 + 9e3984f commit 10be4d6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Symfony/Component/AssetMapper/Factory/MappedAssetFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@ private function isVendor(string $sourcePath): bool
128128
$sourcePath = realpath($sourcePath);
129129
$vendorDir = realpath($this->vendorDir);
130130

131-
return $sourcePath && str_starts_with($sourcePath, $vendorDir);
131+
return $sourcePath && $vendorDir && str_starts_with($sourcePath, $vendorDir);
132132
}
133133
}

src/Symfony/Component/AssetMapper/Tests/Factory/MappedAssetFactoryTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
class MappedAssetFactoryTest extends TestCase
2828
{
29+
private const DEFAULT_FIXTURES = __DIR__.'/../Fixtures/assets/vendor';
30+
2931
private AssetMapperInterface&MockObject $assetMapper;
3032

3133
public function testCreateMappedAsset()
@@ -137,7 +139,15 @@ public function testCreateMappedAssetInVendor()
137139
$this->assertTrue($asset->isVendor);
138140
}
139141

140-
private function createFactory(?AssetCompilerInterface $extraCompiler = null): MappedAssetFactory
142+
public function testCreateMappedAssetInMissingVendor()
143+
{
144+
$assetMapper = $this->createFactory(null, '/this-path-does-not-exist/');
145+
$asset = $assetMapper->createMappedAsset('lodash.js', __DIR__.'/../Fixtures/assets/vendor/lodash/lodash.index.js');
146+
$this->assertSame('lodash.js', $asset->logicalPath);
147+
$this->assertFalse($asset->isVendor);
148+
}
149+
150+
private function createFactory(?AssetCompilerInterface $extraCompiler = null, ?string $vendorDir = self::DEFAULT_FIXTURES): MappedAssetFactory
141151
{
142152
$compilers = [
143153
new JavaScriptImportPathCompiler($this->createMock(ImportMapConfigReader::class)),
@@ -162,7 +172,7 @@ private function createFactory(?AssetCompilerInterface $extraCompiler = null): M
162172
$factory = new MappedAssetFactory(
163173
$pathResolver,
164174
$compiler,
165-
__DIR__.'/../Fixtures/assets/vendor',
175+
$vendorDir,
166176
);
167177

168178
// mock the AssetMapper to behave like normal: by calling back to the factory

0 commit comments

Comments
 (0)
0