Application example

#[Package('core')] class CommandExecutor
{
    private readonly Application $application;

    /** * @internal */
    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,
                
return true;
    }

    private function getCommandTester(): CommandTester
    {
        $themeCreateCommand = new ThemeCreateCommand(
            $this->projectDir
        );

        $commandTester = new CommandTester($themeCreateCommand);
        $application = new Application();
        $application->add($themeCreateCommand);

        return $commandTester;
    }
}
static::assertDirectoryExists($this->testDir, 'Testdir: ' . $this->testDir . ' not found!');
        $testFiles = glob($this->testDir . 'processed/*');
        static::assertIsArray($testFiles);
        @array_map('unlink', $testFiles);
        @rmdir($this->testDir . 'processed');
    }

    public function testThemePrepareIconsCommandMissingPackageArg(): void
    {
        $command = new ThemePrepareIconsCommand();
        $commandTester = new CommandTester($command);
        $application = new Application();
        $application->add($command);

        static::expectExceptionMessage('Not enough arguments (missing: "package")');
        $commandTester->execute([
            'path' => $this->testDir,
        ]);
    }

    public function testThemePrepareIconsCommandMissingPathArg(): void
    {
        $command = new ThemePrepareIconsCommand();
        


        $errors = array_filter($errors);
        $errorMessage = 'Found some issues in the following files:' . \PHP_EOL . \PHP_EOL . print_r($errors, true);

        static::assertCount(0, $errors$errorMessage);
    }

    public function testContainerLintCommand(): void
    {
        $command = $this->getContainer()->get('console.command.container_lint');
        $command->setApplication(new Application(KernelLifecycleManager::getKernel()));
        $commandTester = new CommandTester($command);

        set_error_handler(fn (): bool => true, \E_USER_DEPRECATED);
        $commandTester->execute([]);
        restore_error_handler();

        static::assertEquals(
            0,
            $commandTester->getStatusCode(),
            "\"bin/console lint:container\" returned errors:\n" . $commandTester->getDisplay()
        );
    }
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
        }

        $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()
            ),
return;
        }

        (new Filesystem())->remove($directory);
    }

    private function getCommandTester(): CommandTester
    {
        $appCreateCommand = new CreateAppCommand($this->appLifecycle, $this->appDir);

        $commandTester = new CommandTester($appCreateCommand);
        $application = new Application();
        $application->add($appCreateCommand);

        return $commandTester;
    }
}
$themeService->expects(static::exactly(\count($salesChannels)))
            ->method('assignTheme');

        $themeChangeCommand = new ThemeChangeCommand(
            $themeService,
            $this->pluginRegistry,
            $this->salesChannelRepository,
            $this->themeRepository
        );

        $commandTester = new CommandTester($themeChangeCommand);
        $application = new Application();
        $application->add($themeChangeCommand);

        $commandTester->execute([
            'theme-name' => $themes[0]['technicalName'],
            '--all' => true,
        ]);
    }

    public function testThemeChangeCommandWithOneSalesChannel(): void
    {
        $context = Context::createDefaultContext();

        
use Shopware\Core\DevOps\StaticAnalyze\StaticAnalyzeKernel;
use Shopware\Core\Framework\Plugin\KernelPluginLoader\StaticKernelPluginLoader;
use Symfony\Bundle\FrameworkBundle\Console\Application;

$classLoader = require __DIR__ . '/phpstan-bootstrap.php';

$pluginLoader = new StaticKernelPluginLoader($classLoader);

$kernel = new StaticAnalyzeKernel('phpstan_dev', true, $pluginLoader, 'phpstan-test-cache-id');
$kernel->boot();

return new Application($kernel);
Home | Imprint | This part of the site doesn't use cookies.