ArrayInput example

foreach ($commands as $parameters) {
            // remove params with null value             $parameters = array_filter($parameters);

            $output->writeln('');

            $command = $application->find((string) $parameters['command']);
            $allowedToFail = $parameters['allowedToFail'] ?? false;
            unset($parameters['command']$parameters['allowedToFail']);

            try {
                $returnCode = $command->run(new ArrayInput($parameters$command->getDefinition())$output);
                if ($returnCode !== 0 && !$allowedToFail) {
                    return $returnCode;
                }
            } catch (\Throwable $e) {
                if (!$allowedToFail) {
                    throw $e;
                }
            }
        }

        return self::SUCCESS;
    }
$context = $this->getSalesChannelContext($redisCart->getToken());

        $factory = new RedisConnectionFactory('test-prefix-');
        $redis = $factory->create((string) $url);
        static::assertInstanceOf(\Redis::class$redis);
        $redis->flushAll();

        $persister = new RedisCartPersister($redis$this->getContainer()->get('event_dispatcher')$this->getContainer()->get(CartSerializationCleaner::class), false, 90);
        $persister->save($redisCart$context);

        $command = new CartMigrateCommand($redis$this->getContainer()->get(Connection::class), false, 90, $factory);
        $command->run(new ArrayInput(['from' => 'redis'])new NullOutput());

        $persister = new CartPersister(
            $this->getContainer()->get(Connection::class),
            $this->getContainer()->get('event_dispatcher'),
            $this->getContainer()->get(CartSerializationCleaner::class),
            false
        );

        $persister->load($redisCart->getToken()$context);
    }

    
'database:migrate-destructive',
            'system:configure-shop',
            'dal:refresh:index',
            'scheduled-task:register',
            'plugin:refresh',
            'theme:refresh',
            'theme:compile',
            'assets:install',
            'cache:clear',
        ]);

        $result = $command->run(new ArrayInput([])new BufferedOutput());

        static::assertEquals(0, $result);
    }

    public function testBasicSetupFlow(): void
    {
        $command = $this->prepareCommandInstance([
            'system:generate-jwt',
            'database:migrate',
            'database:migrate-destructive',
            'system:configure-shop',
            
->get(AdminElasticsearchHelper::class)
            ->setEnabled(false);
    }

    /** * @param array<string, mixed> $input */
    public function indexElasticSearch(array $input = []): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchAdminIndexingCommand::class)
            ->run(new ArrayInput([...$input, '--no-queue' => true])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }
$connection = $this->getContainer()->get(Connection::class);

        $connection->executeStatement('DELETE FROM custom_field');

        $command = new ElasticsearchIndexingCommand(
            $this->getContainer()->get(ElasticsearchIndexer::class),
            $this->getContainer()->get('messenger.bus.shopware'),
            $this->getContainer()->get(CreateAliasTaskHandler::class),
            true
        );

        $command->run(new ArrayInput([])new NullOutput());

        static::assertNotEmpty($this->indexDetector->getAllUsedIndices());
    }

    /** * @depends testCreateIndices */
    public function testCreateCustomFields(): void
    {
        $customFieldRepository = $this->getContainer()->get('custom_field_set.repository');
        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            
->with('SELECT JSON_OVERLAPS(JSON_ARRAY(1), JSON_ARRAY(1));')
            ->willThrowException(new \Exception('Not available'));

        $command = new DeleteNotUsedMediaCommand($service$connection);

        $commandTester = new CommandTester($command);
        $commandTester->execute([]);

        $output = new BufferedOutput();

        $io = new SymfonyStyle(
            new ArrayInput([]),
            $output,
        );

        $io->error('Your database does not support the JSON_OVERLAPS function. Please update your database to MySQL 8.0 or MariaDB 10.9 or higher.');

        static::assertStringContainsString($output->fetch()$commandTester->getDisplay());
    }

    public function testExecuteWithConfirm(): void
    {
        $service = $this->createMock(UnusedMediaPurger::class);

        

    public function __construct(private readonly string $projectDir)
    {
        $this->application = new Application();
        $this->application->setAutoExit(false);
    }

    public function require(string $pluginComposerName, string $pluginName): void
    {
        $output = new BufferedOutput();
        $input = new ArrayInput(
            [
                'command' => 'require',
                'packages' => [$pluginComposerName],
                '--working-dir' => $this->projectDir,
                '--no-interaction' => null,
                '--update-with-dependencies' => null,
                '--no-scripts' => null,
            ]
        );

        $exitCode = $this->application->run($input$output);

        
public function disableElasticsearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchHelper::class)
            ->setEnabled(false);
    }

    public function indexElasticSearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchIndexingCommand::class)
            ->run(new ArrayInput([])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

        ]$coverageReport['js']);
    }

    /** * @param mixed[] $parameters */
    private function runCommand(array $parameters): string
    {
        $getClassesCommand = new SummarizeCoverageReports($this->getProjectDir()new Environment(new ArrayLoader()));
        $definition = $getClassesCommand->getDefinition();
        $input = new ArrayInput(
            $parameters,
            $definition
        );
        $input->getOptions();
        $output = new BufferedOutput();

        $refMethod = ReflectionHelper::getMethod(SummarizeCoverageReports::class, 'execute');
        $refMethod->invoke($getClassesCommand$input$output);

        return $output->fetch();
    }

    


    /** * @param mixed[] $parameters */
    private function runCommand(array $parameters): string
    {
        $projectDir = $this->getProjectDir();

        $getClassesCommand = new GetClassesPerAreaCommand($projectDir);
        $definition = $getClassesCommand->getDefinition();
        $input = new ArrayInput(
            $parameters,
            $definition
        );
        $input->getOptions();
        $output = new BufferedOutput();

        $refMethod = ReflectionHelper::getMethod(GetClassesPerAreaCommand::class, 'execute');
        $refMethod->invoke($getClassesCommand$input$output);

        return $output->fetch();
    }

    

        ];
    }

    /** * @param mixed[] $parameters */
    private function runCommand(array $parameters): string
    {
        $getClassesCommand = new GetJSFilesPerAreaCommand();
        $definition = $getClassesCommand->getDefinition();
        $input = new ArrayInput(
            $parameters,
            $definition
        );
        $input->getOptions();
        $output = new BufferedOutput();

        $refMethod = ReflectionHelper::getMethod(GetJSFilesPerAreaCommand::class, 'execute');
        $refMethod->invoke($getClassesCommand$input$output);

        return $output->fetch();
    }
}

        return $this->getContainer()->get(MigrationDestructiveCommand::class);
    }

    public function testCommandMigrateNoUntilNoAllOption(): void
    {
        static::assertSame(0, $this->getMigrationCount(true));

        $command = $this->getCommand();

        $this->expectException(\InvalidArgumentException::class);
        $command->run(new ArrayInput([])new BufferedOutput());
    }

    public function testCommandMigrateAllOption(): void
    {
        static::assertSame(0, $this->getMigrationCount());

        $command = $this->getCommand();

        $command->run(new ArrayInput(['-all' => true, 'identifier' => self::INTEGRATION_IDENTIFIER()])new BufferedOutput());

        static::assertSame(2, $this->getMigrationCount());
    }

        $application = $this->getApplication();
        if ($application === null) {
            throw new \RuntimeException('No application initialised');
        }
        $command = $application->find('database:migrate');

        $arguments = [
            'identifier' => 'core',
            '--all' => true,
        ];
        $arrayInput = new ArrayInput($arguments$command->getDefinition());

        return $command->run($arrayInput$output);
    }

    private function installAssets(OutputInterface $output): int
    {
        $application = $this->getApplication();
        if ($application === null) {
            throw new \RuntimeException('No application initialised');
        }
        $command = $application->find('assets:install');

        
$result = new SitemapGenerationResult(true, null, null, $storefrontId, Defaults::LANGUAGE_SYSTEM);

        $this->exporter->expects(static::once())
            ->method('generate')
            ->with(static::callback(function DSalesChannelContext $context) use ($storefrontId) {
                static::assertSame($storefrontId$context->getSalesChannelId());

                return true;
            }))
            ->willReturn($result);

        $input = new ArrayInput([]);
        $this->command->run($inputnew NullOutput());
    }
}
$envFilePath = $this->getProjectDir() . '/.env';
        if (\is_file($envFilePath) || \is_file($envFilePath . '.dist') || \is_file($envFilePath . '.local.php')) {
            (new Dotenv())->usePutenv()->bootEnv($envFilePath);
        }
    }

    private function install(): void
    {
        $installCommand = (new Application($this->getKernel()))->find('system:install');

        $returnCode = $installCommand->run(
            new ArrayInput(
                [
                    '--create-database' => true,
                    '--force' => true,
                    '--drop-database' => true,
                    '--basic-setup' => true,
                    '--no-assign-theme' => true,
                ],
                $installCommand->getDefinition()
            ),
            $this->getOutput()
        );
        
Home | Imprint | This part of the site doesn't use cookies.