ExtensionCollection example

'name' => $e->getName(),
                'version' => $e->getVersion(),
            ]$extensions->getElements())];

            $response = $this->fetchLicenses($payload$context);
        } catch (ClientException $e) {
            throw new StoreApiException($e);
        }

        $body = \json_decode($response->getBody()->getContents(), true, flags: \JSON_THROW_ON_ERROR);

        $myExtensions = new ExtensionCollection();

        foreach ($body as $item) {
            $extension = $this->extensionLoader->loadFromArray($context$item['extension']);
            $extension->setSource(ExtensionStruct::SOURCE_STORE);
            if (isset($item['license'])) {
                $extension->setStoreLicense(LicenseStruct::fromArray($item['license']));
            }

            if (isset($item['update'])) {
                $extension->setVersion($item['update']['installedVersion']);
                $extension->setLatestVersion($item['update']['availableVersion']);
                


        // secret from login.json         static::assertEquals(
            'shop.secret',
            $this->configService->get('core.store.shopSecret')
        );
    }

    public function testItRequestsUpdatesForLoggedInUser(): void
    {
        $pluginList = new ExtensionCollection();
        $pluginList->add((new ExtensionStruct())->assign([
            'name' => 'TestExtension',
            'version' => '1.0.0',
        ]));

        $this->getRequestHandler()->append(new Response(200, [], \json_encode([
            'data' => [],
        ], \JSON_THROW_ON_ERROR)));

        $updateList = $this->storeClient->getExtensionUpdateList($pluginList$this->storeContext);

        
continue;
            }

            $localCollection->set($storeExtension->getName()$storeExtension);
        }
    }

    private function sortCollection(ExtensionCollection $collection): ExtensionCollection
    {
        $collection->sort(fn (ExtensionStruct $a, ExtensionStruct $b) => strcmp($a->getLabel()$b->getLabel()));

        $sortedCollection = new ExtensionCollection();

        // Sorted order: active, installed, all others         foreach ($collection->getElements() as $extension) {
            if ($extension->getActive()) {
                $sortedCollection->set($extension->getName()$extension);
                $collection->remove($extension->getName());
            }
        }

        foreach ($collection->getElements() as $extension) {
            if ($extension->getInstalledAt()) {
                

        $this->extensionListingLoader = $this->getContainer()->get(ExtensionListingLoader::class);
    }

    public function testServerNotReachable(): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(function D): void {
            throw new ClientException('', new Request('GET', '')new Response(500, [], ''));
        });

        $collection = new ExtensionCollection();
        $collection->set('myPlugin', (new ExtensionStruct())->assign(['name' => 'myPlugin', 'label' => 'Label', 'version' => '1.0.0']));
        $collection = $this->extensionListingLoader->load($collection$this->createAdminStoreContext());

        static::assertCount(1, $collection);
    }

    public function testExternalAreAdded(): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '{"data":[]}'));
        $this->getRequestHandler()->append(new Response(200, []$this->getLicencesJson()));

        


    public function getExtensionDataProvider(): AbstractExtensionDataProvider&MockObject
    {
        $extension = new ExtensionStruct();
        $extension->setName('TestApp');
        $extension->setActive(true);

        $extensionDataProvider = $this->createMock(AbstractExtensionDataProvider::class);
        $extensionDataProvider
            ->method('getInstalledExtensions')
            ->willReturn(new ExtensionCollection(['TestApp' => $extension]));

        return $extensionDataProvider;
    }

    public function getStoreClient(string $file = __DIR__ . './../_fixtures/responses/extension-red.json'): StoreClient&MockObject
    {
        $storeClient = $this->createMock(StoreClient::class);
        $storeClient->method('getExtensionCompatibilities')->willReturn(json_decode((string) file_get_contents($file), true, 512, \JSON_THROW_ON_ERROR));

        return $storeClient;
    }
}
return ExtensionStruct::fromArray($data);
    }

    /** * @param array<array<string, mixed>> $data */
    public function loadFromListingArray(Context $context, array $data): ExtensionCollection
    {
        $locale = $this->localeProvider->getLocaleFromContext($context);
        $localeWithUnderscore = str_replace('-', '_', $locale);
        $extensions = new ExtensionCollection();

        foreach ($data as $extension) {
            $extension = ExtensionStruct::fromArray($this->prepareArrayData($extension$localeWithUnderscore));
            $extensions->set($extension->getName()$extension);
        }

        return $extensions;
    }

    public function loadFromAppCollection(Context $context, AppCollection $collection): ExtensionCollection
    {
        
Home | Imprint | This part of the site doesn't use cookies.