resolvePackages example

final class PackageResolver implements PackageResolverInterface
{
    public function __construct(
        private readonly string $provider,
        private readonly ContainerInterface $locator,
    ) {
    }

    public function resolvePackages(array $packagesToRequire): array
    {
        return $this->locator->get($this->provider)
            ->resolvePackages($packagesToRequire);
    }
}
return new MockResponse(json_encode($responseData));
        };
        // mock the "file download" requests         foreach ($expectedDownloadedFiles as $file) {
            $responses[] = new MockResponse(sprintf('contents of %s', $file));
        }

        $httpClient = new MockHttpClient($responses);

        $provider = new JspmResolver($httpClient, ImportMapManager::PROVIDER_JSPM);
        $actualResolvedPackages = $provider->resolvePackages($packages);
        $this->assertCount(\count($expectedResolvedPackages)$actualResolvedPackages);
        foreach ($actualResolvedPackages as $package) {
            $packageName = $package->requireOptions->packageName;
            $this->assertArrayHasKey($packageName$expectedResolvedPackages);
            $this->assertSame($expectedResolvedPackages[$packageName]['url']$package->url);
        }
    }

    public static function provideResolvePackagesTests(): iterable
    {
        yield 'require single lodash package' => [
            


                return new MockResponse($body[
                    'url' => $expectedRequest['response']['url'] ?? '/anything',
                ]);
            };
        }

        $httpClient = new MockHttpClient($responses);

        $provider = new JsDelivrEsmResolver($httpClient);
        $actualResolvedPackages = $provider->resolvePackages($packages);
        $this->assertCount(\count($expectedResolvedPackages)$actualResolvedPackages);
        foreach ($actualResolvedPackages as $package) {
            $packageName = $package->requireOptions->packageName;
            $this->assertArrayHasKey($packageName$expectedResolvedPackages);
            $this->assertSame($expectedResolvedPackages[$packageName]['url']$package->url);
            if (isset($expectedResolvedPackages[$packageName]['content'])) {
                $this->assertSame($expectedResolvedPackages[$packageName]['content']$package->content);
            }
        }
    }

    
$requireOptions->preload,
            );
            $importMapEntries[$requireOptions->packageName] = $newEntry;
            $addedEntries[] = $newEntry;
            unset($packagesToRequire[$key]);
        }

        if (!$packagesToRequire) {
            return $addedEntries;
        }

        $resolvedPackages = $this->resolver->resolvePackages($packagesToRequire);
        foreach ($resolvedPackages as $resolvedPackage) {
            $importName = $resolvedPackage->requireOptions->importName ?: $resolvedPackage->requireOptions->packageName;
            $path = null;
            if ($resolvedPackage->requireOptions->download) {
                if (null === $resolvedPackage->content) {
                    throw new \LogicException(sprintf('The contents of package "%s" were not downloaded.', $resolvedPackage->requireOptions->packageName));
                }

                $path = $this->downloadPackage($importName$resolvedPackage->content);
            }

            
Home | Imprint | This part of the site doesn't use cookies.