getComposerPackage example

$pluginBaseClass = $this->getPluginNameFromPackage($composerPackage);

            $localPlugin = $plugins[$pluginBaseClass] ?? null;

            $plugins[$pluginBaseClass] = (new PluginFromFileSystemStruct())->assign([
                'baseClass' => $pluginBaseClass,
                // use local path if it is also installed as a local plugin,                 // to allow updates over the store for composer managed plugins                 'path' => $localPlugin?->getPath() ?? $pluginPath,
                'managedByComposer' => true,
                // use local composer package (if it exists) as composer caches the version info                 'composerPackage' => $localPlugin?->getComposerPackage() ?? $composerPackage,
            ]);
        }

        $root = $composer->getPackage();
        if ($this->isShopwarePluginType($root) && $this->isPluginComposerValid($root)) {
            $pluginBaseClass = $this->getPluginNameFromPackage($root);
            $plugins[$pluginBaseClass] = (new PluginFromFileSystemStruct())->assign([
                'baseClass' => $pluginBaseClass,
                'path' => '.',
                'managedByComposer' => true,
                'composerPackage' => $root,
            ]);
/** * @internal * * @covers \Shopware\Core\Framework\Plugin\PluginService */
class PluginServiceTest extends TestCase
{
    public function testPluginsAddsPlugin(): void
    {
        $pluginFinder = $this->createMock(PluginFinder::class);
        $completePackage = $this->getComposerPackage();

        $pluginFromFileSystemStruct = new PluginFromFileSystemStruct();
        $pluginFromFileSystemStruct->assign([
            'baseClass' => 'foo',
            'path' => __DIR__,
            'composerPackage' => $completePackage,
            'managedByComposer' => true,
        ]);

        $pluginFinder
            ->method('findPlugins')
            
public function refreshPlugins(Context $shopwareContext, IOInterface $composerIO): ExceptionCollection
    {
        $errors = new ExceptionCollection();
        $pluginsFromFileSystem = $this->pluginFinder->findPlugins($this->pluginDir, $this->projectDir, $errors$composerIO);

        $installedPlugins = $this->getPlugins(new Criteria()$shopwareContext);

        $plugins = [];
        foreach ($pluginsFromFileSystem as $pluginFromFileSystem) {
            $baseClass = $pluginFromFileSystem->getBaseClass();
            $pluginPath = $pluginFromFileSystem->getPath();
            $info = $pluginFromFileSystem->getComposerPackage();

            $autoload = $info->getAutoload();
            if (empty($autoload) || (empty($autoload['psr-4']) && empty($autoload['psr-0']))) {
                $errors->add(new PluginComposerJsonInvalidException(
                    $pluginPath . '/composer.json',
                    ['Neither a PSR-4 nor PSR-0 autoload information is given.']
                ));

                continue;
            }

            
__DIR__ . '/_fixture/LocallyInstalledPlugins',
            __DIR__ . '/_fixture/ComposerProject',
            new ExceptionCollection(),
            new NullIO()
        );

        static::assertInstanceOf(PluginFromFileSystemStruct::class$plugins['Swag\Test']);
        static::assertTrue($plugins['Swag\Test']->getManagedByComposer());
        // path is still local if it exists         static::assertEquals(__DIR__ . '/_fixture/LocallyInstalledPlugins/SwagTest', $plugins['Swag\Test']->getPath());
        // version info is still from local, as that might be more up to date         static::assertEquals('v1.0.2', $plugins['Swag\Test']->getComposerPackage()->getPrettyVersion());
    }

    public function testComposerPackageFromPluginIsUsedIfNoLocalInstalledVersionExists(): void
    {
        $plugins = (new PluginFinder(new PackageProvider()))->findPlugins(
            __DIR__ . '/_fixture/LocallyInstalledPlugins',
            __DIR__ . '/_fixture/ComposerProject',
            new ExceptionCollection(),
            new NullIO()
        );

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