NullIO example

public function __construct(
        private readonly AbstractExtensionLifecycle $extensionLifecycleService,
        private readonly ExtensionDownloader $extensionDownloader,
        private readonly PluginService $pluginService,
        private readonly PluginManagementService $pluginManagementService
    ) {
    }

    #[Route(path: '/api/_action/extension/refresh', name: 'api.extension.refresh', methods: ['POST'])]     public function refreshExtensions(Context $context): Response
    {
        $this->pluginService->refreshPlugins($contextnew NullIO());

        return new Response('', Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/extension/upload', name: 'api.extension.upload', methods: ['POST'], defaults: ['_acl' => ['system.plugin_upload']])]     public function uploadExtensions(Request $request, Context $context): Response
    {
        /** @var UploadedFile|null $file */
        $file = $request->files->get('file');

        if (!$file) {
            
use Composer\IO\NullIO;
use Shopware\Core\DevOps\Environment\EnvironmentHelper;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Kernel;

#[Package('core')] class Factory
{
    public static function createComposer(string $composerJsonDir, ?IOInterface $composerIO = null): Composer
    {
        if ($composerIO === null) {
            $composerIO = new NullIO();
        }

        $composerJsonPath = $composerJsonDir . '/composer.json';

        $json = json_decode((string) file_get_contents($composerJsonPath), true, \JSON_THROW_ON_ERROR);

        $previousRootVersion = EnvironmentHelper::hasVariable('COMPOSER_ROOT_VERSION') ? EnvironmentHelper::getVariable('COMPOSER_ROOT_VERSION') : null;

        // This is a workaround to make sure that the shopware platform package has the correct version         if (($json['name'] ?? '') === 'shopware/platform' && !isset($json['version']) && !EnvironmentHelper::hasVariable('COMPOSER_ROOT_VERSION')) {
            $_SERVER['COMPOSER_ROOT_VERSION'] = Kernel::SHOPWARE_FALLBACK_VERSION;
        }
$this->pluginRepo,
            $this->container->get('language.repository'),
            $this->container->get(PluginFinder::class)
        );

        $this->addTestPluginToKernel(
            __DIR__ . '/_fixture/plugins/SwagManualMigrationTest',
            'SwagManualMigrationTest'
        );
        $this->requireMigrationFiles();

        $this->pluginService->refreshPlugins($this->context, new NullIO());
        $this->connection->executeStatement('DELETE FROM plugin WHERE `name` = "SwagTest"');
    }

    public function testInstall(): MigrationCollection
    {
        static::assertSame(0, $this->connection->getTransactionNestingLevel());

        $migrationPlugin = $this->getMigrationTestPlugin();
        static::assertNull($migrationPlugin->getInstalledAt());

        $this->pluginLifecycleService->installPlugin($migrationPlugin$this->context);
        
$extensions = $this->extensionLoader->loadFromListingArray(
            Context::createDefaultContext(),
            $listingResponse
        );

        static::assertInstanceOf(ExtensionCollection::class$extensions);
        static::assertCount(2, $extensions);
    }

    public function testItLoadsExtensionsFromPlugins(): void
    {
        $this->getContainer()->get(PluginService::class)->refreshPlugins(Context::createDefaultContext()new NullIO());

        /** @var PluginCollection $plugins */
        $plugins = $this->getContainer()->get('plugin.repository')->search(new Criteria(), Context::createDefaultContext())->getEntities();

        $extensions = $this->extensionLoader->loadFromPluginCollection(Context::createDefaultContext()$plugins);

        /** @var ExtensionStruct $extension */
        $extension = $extensions->get('AppStoreTestPlugin');

        static::assertNotNull($extension);
        static::assertEquals('AppStoreTestPlugin', $extension->getName());
    }
$this->getContainer()->getParameter('kernel.project_dir'),
            $this->pluginRepository,
            $this->languageRepository,
            $this->pluginFinder
        );

        $this->addTestPluginToKernel(
            __DIR__ . '/_fixtures/plugins/' . self::PLUGIN_NAME,
            self::PLUGIN_NAME
        );

        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $this->pluginLifecycleService->installPlugin(
            $this->pluginService->getPluginByName(
                self::PLUGIN_NAME,
                $this->context
            ),
            $this->context
        );

        $installedPlugin = $this->pluginService->getPluginByName(self::PLUGIN_NAME, $this->context);
        static::assertNotNull($installedPlugin->getInstalledAt());

        
/** @var string $tempFileName */
        $tempFileName = tempnam(sys_get_temp_dir()$file->getClientOriginalName());
        $tempRealPath = realpath($tempFileName);
        \assert(\is_string($tempRealPath));
        $tempDirectory = \dirname($tempRealPath);

        $tempFile = $file->move($tempDirectory$tempFileName);

        $type = $this->extractPluginZip($tempFile->getPathname());

        if ($type === self::PLUGIN) {
            $this->pluginService->refreshPlugins($contextnew NullIO());
        }
    }

    public function downloadStorePlugin(PluginDownloadDataStruct $location, Context $context): void
    {
        /** @var string $tempFileName */
        $tempFileName = tempnam(sys_get_temp_dir(), 'store-plugin');

        try {
            $response = $this->client->request('GET', $location->getLocation()['sink' => $tempFileName]);
        } catch (\Exception) {
            
$plugin = $this->getTestPlugin($context);
        static::assertFalse($plugin->getActive());
    }

    public function testDeactivatePluginWithDependencies(): void
    {
        $this->addTestPluginToKernel(
            __DIR__ . '/_fixture/plugins/' . self::DEPENDENT_PLUGIN_NAME,
            self::DEPENDENT_PLUGIN_NAME
        );
        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $basePlugin = $this->pluginService->getPluginByName(self::PLUGIN_NAME, $this->context);
        $this->pluginLifecycleService->installPlugin($basePlugin$this->context);
        $this->pluginLifecycleService->activatePlugin($basePlugin$this->context);

        $dependentPlugin = $this->pluginService->getPluginByName(self::DEPENDENT_PLUGIN_NAME, $this->context);
        $this->pluginLifecycleService->installPlugin($dependentPlugin$this->context);
        $this->pluginLifecycleService->activatePlugin($dependentPlugin$this->context);

        $this->expectException(PluginHasActiveDependantsException::class);

        
if ($pluginBaseClass->executeComposerCommands()) {
            $pluginComposerName = $plugin->getComposerName();
            if ($pluginComposerName === null) {
                throw new PluginComposerJsonInvalidException(
                    $pluginBaseClass->getPath() . '/composer.json',
                    ['No name defined in composer.json']
                );
            }
            $this->executor->remove($pluginComposerName$plugin->getName());

            // running composer require may have consequences for other plugins, when they are required by the plugin being uninstalled             $this->pluginService->refreshPlugins($shopwareContextnew NullIO());
        }

        $this->eventDispatcher->dispatch(new PluginPostUninstallEvent($plugin$uninstallContext));

        return $uninstallContext;
    }

    /** * @throws RequirementStackException */
    public function updatePlugin(PluginEntity $plugin, Context $shopwareContext): UpdateContext
    {
__DIR__ . '/_fixture/plugins',
            $this->getContainer()->getParameter('kernel.project_dir'),
            $this->pluginRepo,
            $this->getContainer()->get('language.repository'),
            $this->getContainer()->get(PluginFinder::class)
        );
        $this->context = Context::createDefaultContext();
    }

    public function testRefreshPlugins(): void
    {
        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $plugin = $this->fetchSwagTestPluginEntity();

        $this->assertDefaultPlugin($plugin);
        $this->assertPluginMetaInformation($plugin);
        static::assertSame('English description', $plugin->getDescription());
        static::assertSame('https://www.test.com/', $plugin->getManufacturerLink());
        static::assertSame('https://www.test.com/support', $plugin->getSupportLink());
    }

    public function testRefreshPluginWithoutExtraLabelProperty(): void
    {
use Shopware\Core\Framework\Plugin\Exception\PluginComposerJsonInvalidException;

/** * @internal */
class PackageProviderTest extends TestCase
{
    public function testGetPluginInformation(): void
    {
        $packageProvider = $this->createProvider();
        $pluginPath = __DIR__ . '/_fixture/valid';
        $package = $packageProvider->getPluginComposerPackage($pluginPathnew NullIO());

        static::assertSame('test/test', $package->getName());
    }

    public function testGetPluginInformationInvalidJson(): void
    {
        $packageProvider = $this->createProvider();
        $pluginPath = __DIR__ . '/_fixture/invalid';

        $this->expectException(PluginComposerJsonInvalidException::class);
        $this->expectExceptionMessage('name : The property name is required');
        

class PluginFinderTest extends TestCase
{
    public function testFailsOnMissingRootComposerFile(): void
    {
        $errors = new ExceptionCollection();
        (new PluginFinder(new PackageProvider()))->findPlugins(
            __DIR__,
            __DIR__ . '/../../../../../..',
            $errors,
            new NullIO()
        );

        static::assertInstanceOf(PluginComposerJsonInvalidException::class$errors->first());
    }

    public function testLocalLoadsTheComposerJsonContents(): void
    {
        $plugins = (new PluginFinder(new PackageProvider()))->findPlugins(
            __DIR__ . '/_fixture/LocallyInstalledPlugins',
            __DIR__ . '/_fixture/ComposerProject',
            new ExceptionCollection(),
            
Home | Imprint | This part of the site doesn't use cookies.