Skip to content

Commit

Permalink
fix: ignore missing directory in isVendor()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre authored and nicolas-grekas committed Nov 20, 2024
1 parent 21fe29b commit 64fb7ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Factory/MappedAssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ private function isVendor(string $sourcePath): bool
$sourcePath = realpath($sourcePath);
$vendorDir = realpath($this->vendorDir);

return $sourcePath && str_starts_with($sourcePath, $vendorDir);
return $sourcePath && $vendorDir && str_starts_with($sourcePath, $vendorDir);
}
}
14 changes: 12 additions & 2 deletions Tests/Factory/MappedAssetFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

class MappedAssetFactoryTest extends TestCase
{
private const DEFAULT_FIXTURES = __DIR__.'/../Fixtures/assets/vendor';

private AssetMapperInterface&MockObject $assetMapper;

public function testCreateMappedAsset()
Expand Down Expand Up @@ -137,7 +139,15 @@ public function testCreateMappedAssetInVendor()
$this->assertTrue($asset->isVendor);
}

private function createFactory(?AssetCompilerInterface $extraCompiler = null): MappedAssetFactory
public function testCreateMappedAssetInMissingVendor()
{
$assetMapper = $this->createFactory(null, '/this-path-does-not-exist/');
$asset = $assetMapper->createMappedAsset('lodash.js', __DIR__.'/../Fixtures/assets/vendor/lodash/lodash.index.js');
$this->assertSame('lodash.js', $asset->logicalPath);
$this->assertFalse($asset->isVendor);
}

private function createFactory(?AssetCompilerInterface $extraCompiler = null, ?string $vendorDir = self::DEFAULT_FIXTURES): MappedAssetFactory
{
$compilers = [
new JavaScriptImportPathCompiler($this->createMock(ImportMapConfigReader::class)),
Expand All @@ -162,7 +172,7 @@ private function createFactory(?AssetCompilerInterface $extraCompiler = null): M
$factory = new MappedAssetFactory(
$pathResolver,
$compiler,
__DIR__.'/../Fixtures/assets/vendor',
$vendorDir,
);

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

0 comments on commit 64fb7ab

Please sign in to comment.