createAssetMapper example

class JavaScriptImportPathCompilerTest extends TestCase
{
    /** * @dataProvider provideCompileTests */
    public function testCompile(string $sourceLogicalName, string $input, array $expectedDependencies)
    {
        $asset = new MappedAsset($sourceLogicalName, 'anything', '/assets/'.$sourceLogicalName);

        $compiler = new JavaScriptImportPathCompiler(AssetCompilerInterface::MISSING_IMPORT_IGNORE, $this->createMock(LoggerInterface::class));
        // compile - and check that content doesn't change         $this->assertSame($input$compiler->compile($input$asset$this->createAssetMapper()));
        $actualDependencies = [];
        foreach ($asset->getDependencies() as $dependency) {
            $actualDependencies[$dependency->asset->logicalPath] = $dependency->isLazy;
        }
        $this->assertEquals($expectedDependencies$actualDependencies);
        if ($expectedDependencies) {
            $this->assertFalse($asset->getDependencies()[0]->isContentDependency);
        }
    }

    public static function provideCompileTests(): iterable
    {
'package' => '@hotwired/stimulus',
                'registry' => 'npm',
                'version' => '^1.2.3',
            ],
        ];
    }

    private function createImportMapManager(array $dirs, string $rootDir, string $publicPrefix = '/assets/', string $publicDirName = 'public'): ImportMapManager
    {
        $pathResolver = new PublicAssetsPathResolver($rootDir$publicPrefix$publicDirName);

        $mapper = $this->createAssetMapper($pathResolver$dirs$rootDir);
        $this->packageResolver = $this->createMock(PackageResolverInterface::class);
        $this->httpClient = $this->createMock(HttpClientInterface::class);

        return new ImportMapManager(
            $mapper,
            $pathResolver,
            $rootDir.'/importmap.php',
            $rootDir.'/assets/vendor',
            $this->packageResolver,
            $this->httpClient,
        );
    }
use Symfony\Component\AssetMapper\AssetMapperRepository;
use Symfony\Component\AssetMapper\Factory\MappedAssetFactoryInterface;
use Symfony\Component\AssetMapper\MappedAsset;
use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface;

class AssetMapperTest extends TestCase
{
    private MappedAssetFactoryInterface&MockObject $mappedAssetFactory;

    public function testGetAsset()
    {
        $assetMapper = $this->createAssetMapper();

        $file1Asset = new MappedAsset('file1.css');
        $this->mappedAssetFactory->expects($this->once())
            ->method('createMappedAsset')
            ->with('file1.css', realpath(__DIR__.'/fixtures/dir1/file1.css'))
            ->willReturn($file1Asset);

        $actualAsset = $assetMapper->getAsset('file1.css');
        $this->assertSame($file1Asset$actualAsset);

        $this->assertNull($assetMapper->getAsset('non-existent.js'));
    }
use Symfony\Component\AssetMapper\MappedAsset;

class CssAssetUrlCompilerTest extends TestCase
{
    /** * @dataProvider provideCompileTests */
    public function testCompile(string $sourceLogicalName, string $input, string $expectedOutput, array $expectedDependencies)
    {
        $compiler = new CssAssetUrlCompiler(AssetCompilerInterface::MISSING_IMPORT_IGNORE, $this->createMock(LoggerInterface::class));
        $asset = new MappedAsset($sourceLogicalName, 'anything', '/assets/'.$sourceLogicalName);
        $this->assertSame($expectedOutput$compiler->compile($input$asset$this->createAssetMapper()));
        $assetDependencyLogicalPaths = array_map(fn (AssetDependency $dependency) => $dependency->asset->logicalPath, $asset->getDependencies());
        $this->assertSame($expectedDependencies$assetDependencyLogicalPaths);
        if ($expectedDependencies) {
            $this->assertTrue($asset->getDependencies()[0]->isContentDependency);
        }
    }

    public static function provideCompileTests(): iterable
    {
        yield 'simple_double_quotes' => [
            'sourceLogicalName' => 'styles.css',
            
Home | Imprint | This part of the site doesn't use cookies.