BufferedOutput example

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

    private function getProjectDir(): string
    {
        $vendorDir = key(ClassLoader::getRegisteredLoaders());
        static::assertIsString($vendorDir);

        
/** * @dataProvider provideCheckCommandFixtures * * @param list<string> $expectedOutputSnippets */
    public function testChangelogCheckCommand(string $path, array $expectedOutputSnippets): void
    {
        self::getContainer()->get(ChangelogValidator::class)->setPlatformRoot($path);
        $cmd = self::getContainer()->get(ChangelogCheckCommand::class);

        $output = new BufferedOutput();
        $cmd->run(new StringInput('')$output);

        $outputContents = $output->fetch();

        foreach ($expectedOutputSnippets as $snippet) {
            static::assertStringContainsString($snippet$outputContents);
        }
    }

    /** * @dataProvider provideChangeCommandFixtures * * @param class-string<\Throwable>|null $expectedException * @param list<string> $expectedOutputSnippets */

        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());
    }
/** * @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,
                '--no-interaction' => null,
                '--update-with-dependencies' => null,
                '--no-scripts' => null,
            ]
        );

        
'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',
            
/** @var array<string> $ids */
        $ids = $this->mediaRepository->searchIds(new Criteria()$this->context)->getIds();
        $this->initialMediaIds = $ids;
    }

    public function testExecuteHappyPath(): void
    {
        $this->createValidMediaFiles();

        $input = new StringInput('');
        $output = new BufferedOutput();

        $this->runCommand($this->thumbnailCommand, $input$output);

        $string = $output->fetch();
        static::assertMatchesRegularExpression('/.*Generated\s*2.*/', $string);
        static::assertMatchesRegularExpression('/.*Skipped\s*' . \count($this->initialMediaIds) . '.*/', $string);

        $medias = $this->getNewMediaEntities();
        foreach ($medias as $updatedMedia) {
            $thumbnails = $updatedMedia->getThumbnails();
            static::assertNotNull($thumbnails);
            

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

    private function getProjectDir(): string
    {
        $vendorDir = key(ClassLoader::getRegisteredLoaders());
        static::assertIsString($vendorDir);

        
$connection->expects(static::once())
            ->method('fetchOne')
            ->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());
    }

    
protected function setUp(): void
    {
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->customerRepository = $this->getContainer()->get('customer.repository');
        $this->clearTable('cart');
        $this->clearTable('customer');
    }

    public function testCommandWithoutArguments(): void
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->getCommand()->run($this->getArrayInput()new BufferedOutput());
    }

    public function testCommandWithInvalidArguments(): void
    {
        $input = new ArrayInput(['type' => 'foo']$this->createInputDefinition());

        $this->expectException(\InvalidArgumentException::class);
        $this->getCommand()->run($inputnew BufferedOutput());
    }

    public function testCommandRemovesGuest(): void
    {
/** @var array<string> $ids */
        $ids = $this->mediaRepository->searchIds(new Criteria()$this->context)->getIds();
        $this->initialMediaIds = $ids;
    }

    public function testExecuteHappyPath(): void
    {
        $this->createValidMediaFiles();

        $input = new StringInput('');
        $output = new BufferedOutput();

        $this->runCommand($this->generateMediaTypesCommand, $input$output);

        $mediaResult = $this->getNewMediaEntities();
        /** @var MediaEntity $updatedMedia */
        foreach ($mediaResult as $updatedMedia) {
            static::assertInstanceOf(MediaType::class$updatedMedia->getMediaType());
        }
    }

    public function testExecuteWithCustomBatchSize(): void
    {

    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();
    }
}
$this->productExportGenerateCommand = $this->getContainer()->get(ProductExportGenerateCommand::class);

        $salesChannelContextFactory = $this->getContainer()->get(SalesChannelContextFactory::class);
        $this->salesChannelContext = $salesChannelContextFactory->create(Uuid::randomHex()$this->getSalesChannelDomain()->getSalesChannelId());
    }

    public function testExecute(): void
    {
        $this->createTestEntity();

        $input = new StringInput($this->getSalesChannelDomain()->getSalesChannelId());
        $output = new BufferedOutput();

        $this->runCommand($this->productExportGenerateCommand, $input$output);

        $filePath = sprintf('%s/Testexport.csv', $this->getContainer()->getParameter('product_export.directory'));
        $fileContent = $this->fileSystem->read($filePath);

        static::assertIsString($fileContent);
        $csvRows = explode(\PHP_EOL, $fileContent);

        static::assertTrue($this->fileSystem->directoryExists($this->getContainer()->getParameter('product_export.directory')));
        static::assertTrue($this->fileSystem->fileExists($filePath));

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