AssetMapperRepository example

$mapper,
            $pathResolver,
            $rootDir.'/importmap.php',
            $rootDir.'/assets/vendor',
            $this->packageResolver,
            $this->httpClient,
        );
    }

    private function createAssetMapper(PublicAssetsPathResolverInterface $pathResolver, array $dirs, string $rootDir): AssetMapper
    {
        $repository = new AssetMapperRepository($dirs$rootDir);

        $compiler = new AssetMapperCompiler(
            [new JavaScriptImportPathCompiler()],
            fn () => $this->assetMapper
        );
        $factory = new MappedAssetFactory($pathResolver$compiler);

        $this->assetMapper = new AssetMapper(
            $repository,
            $factory,
            $pathResolver
        );
namespace Symfony\Component\AssetMapper\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\AssetMapper\AssetMapperRepository;
use Symfony\Component\Finder\Glob;

class AssetMapperRepositoryTest extends TestCase
{
    public function testFindWithAbsolutePaths()
    {
        $repository = new AssetMapperRepository([
            __DIR__.'/fixtures/dir1' => '',
            __DIR__.'/fixtures/dir2' => '',
        ], __DIR__);

        $this->assertSame(realpath(__DIR__.'/fixtures/dir1/file1.css')$repository->find('file1.css'));
        $this->assertSame(realpath(__DIR__.'/fixtures/dir2/file4.js')$repository->find('file4.js'));
        $this->assertSame(realpath(__DIR__.'/fixtures/dir2/subdir/file5.js')$repository->find('subdir/file5.js'));
        $this->assertNull($repository->find('file5.css'));
    }

    public function testFindWithRelativePaths()
    {
->method('createMappedAsset')
            ->with('file1.css', realpath(__DIR__.'/fixtures/dir1/file1.css'))
            ->willReturn(new MappedAsset('file1.css'));

        $asset = $assetMapper->getAssetFromSourcePath(__DIR__.'/fixtures/dir1/file1.css');
        $this->assertSame('file1.css', $asset->logicalPath);
    }

    private function createAssetMapper(): AssetMapper
    {
        $dirs = ['dir1' => '', 'dir2' => '', 'dir3' => ''];
        $repository = new AssetMapperRepository($dirs, __DIR__.'/fixtures');
        $pathResolver = $this->createMock(PublicAssetsPathResolverInterface::class);
        $pathResolver->expects($this->any())
            ->method('getPublicFilesystemPath')
            ->willReturn(__DIR__.'/fixtures/test_public/final-assets');

        $this->mappedAssetFactory = $this->createMock(MappedAssetFactoryInterface::class);

        return new AssetMapper(
            $repository,
            $this->mappedAssetFactory,
            $pathResolver,
        );
Home | Imprint | This part of the site doesn't use cookies.