Skip to content

Commit d38fc98

Browse files
fix: ignore missing directory in isVendor()
1 parent 5cc07e7 commit d38fc98

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
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: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626

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

3133
public function testCreateMappedAsset()
3234
{
33-
$factory = $this->createFactory();
35+
$factory = $this->createFactory(self::DEFAULT_FIXTURES);
3436

3537
$asset = $factory->createMappedAsset('file2.js', __DIR__.'/../Fixtures/dir1/file2.js');
3638
$this->assertSame('file2.js', $asset->logicalPath);
@@ -40,7 +42,7 @@ public function testCreateMappedAsset()
4042

4143
public function testCreateMappedAssetRespectsPreDigestedPaths()
4244
{
43-
$assetMapper = $this->createFactory();
45+
$assetMapper = $this->createFactory(self::DEFAULT_FIXTURES);
4446
$asset = $assetMapper->createMappedAsset('already-abcdefVWXYZ0123456789.digested.css', __DIR__.'/../Fixtures/dir2/already-abcdefVWXYZ0123456789.digested.css');
4547
$this->assertSame('already-abcdefVWXYZ0123456789.digested.css', $asset->logicalPath);
4648
$this->assertSame('/final-assets/already-abcdefVWXYZ0123456789.digested.css', $asset->publicPath);
@@ -62,7 +64,7 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
6264
}
6365
};
6466

65-
$assetMapper = $this->createFactory($file1Compiler);
67+
$assetMapper = $this->createFactory(self::DEFAULT_FIXTURES, $file1Compiler);
6668
$expected = 'totally changed';
6769

6870
$asset = $assetMapper->createMappedAsset('file1.css', __DIR__.'/../Fixtures/dir1/file1.css');
@@ -75,15 +77,15 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
7577

7678
public function testCreateMappedAssetWithContentThatDoesNotChange()
7779
{
78-
$assetMapper = $this->createFactory();
80+
$assetMapper = $this->createFactory(self::DEFAULT_FIXTURES);
7981
$asset = $assetMapper->createMappedAsset('file1.css', __DIR__.'/../Fixtures/dir1/file1.css');
8082
// null content because the final content matches the file source
8183
$this->assertNull($asset->content);
8284
}
8385

8486
public function testCreateMappedAssetWithContentErrorsOnCircularReferences()
8587
{
86-
$factory = $this->createFactory();
88+
$factory = $this->createFactory(self::DEFAULT_FIXTURES);
8789

8890
$this->expectException(CircularAssetsException::class);
8991
$this->expectExceptionMessage('Circular reference detected while creating asset for "circular1.css": "circular1.css -> circular2.css -> circular1.css".');
@@ -108,36 +110,47 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
108110
}
109111
};
110112

111-
$factory = $this->createFactory();
113+
$factory = $this->createFactory(self::DEFAULT_FIXTURES);
112114
$asset = $factory->createMappedAsset('subdir/file6.js', __DIR__.'/../Fixtures/dir2/subdir/file6.js');
113115
$this->assertSame('7f983f4053a57f07551fed6099c0da4e', $asset->digest);
114116
$this->assertFalse($asset->isPredigested);
115117

116118
// trigger the compiler, which will change file5.js
117119
// since file6.js imports file5.js, the digest for file6 should change,
118120
// because, internally, the file path in file6.js to file5.js will need to change
119-
$factory = $this->createFactory($file6Compiler);
121+
$factory = $this->createFactory(self::DEFAULT_FIXTURES, $file6Compiler);
120122
$asset = $factory->createMappedAsset('subdir/file6.js', __DIR__.'/../Fixtures/dir2/subdir/file6.js');
121123
$this->assertSame('7e4f24ebddd4ab2a3bcf0d89270b9f30', $asset->digest);
122124
}
123125

124126
public function testCreateMappedAssetWithPredigested()
125127
{
126-
$assetMapper = $this->createFactory();
128+
$assetMapper = $this->createFactory(self::DEFAULT_FIXTURES);
127129
$asset = $assetMapper->createMappedAsset('already-abcdefVWXYZ0123456789.digested.css', __DIR__.'/../Fixtures/dir2/already-abcdefVWXYZ0123456789.digested.css');
128130
$this->assertSame('abcdefVWXYZ0123456789.digested', $asset->digest);
129131
$this->assertTrue($asset->isPredigested);
130132
}
131133

132134
public function testCreateMappedAssetInVendor()
133135
{
134-
$assetMapper = $this->createFactory();
136+
$assetMapper = $this->createFactory(self::DEFAULT_FIXTURES);
135137
$asset = $assetMapper->createMappedAsset('lodash.js', __DIR__.'/../Fixtures/assets/vendor/lodash/lodash.index.js');
136138
$this->assertSame('lodash.js', $asset->logicalPath);
137139
$this->assertTrue($asset->isVendor);
138140
}
139141

140-
private function createFactory(?AssetCompilerInterface $extraCompiler = null): MappedAssetFactory
142+
public function testCreateMappedAssetInMissingVendor()
143+
{
144+
$assetMapper = $this->createFactory(self::DEFAULT_FIXTURES.'/this-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(
151+
string $vendorDir,
152+
?AssetCompilerInterface $extraCompiler = null,
153+
): MappedAssetFactory
141154
{
142155
$compilers = [
143156
new JavaScriptImportPathCompiler($this->createMock(ImportMapConfigReader::class)),
@@ -162,7 +175,7 @@ private function createFactory(?AssetCompilerInterface $extraCompiler = null): M
162175
$factory = new MappedAssetFactory(
163176
$pathResolver,
164177
$compiler,
165-
__DIR__.'/../Fixtures/assets/vendor',
178+
$vendorDir,
166179
);
167180

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy