complete example



    /** * @dataProvider provideCompletionSuggestions */
    public function testComplete(bool $debug, array $input, array $expectedSuggestions)
    {
        $application = $this->createApplication($debug);

        $application->add(new ConfigDebugCommand());
        $tester = new CommandCompletionTester($application->get('debug:config'));
        $suggestions = $tester->complete($input);

        foreach ($expectedSuggestions as $expectedSuggestion) {
            $this->assertContains($expectedSuggestion$suggestions);
        }
    }

    public static function provideCompletionSuggestions(): \Generator
    {
        $name = ['default_config_test', 'extension_without_config_test', 'framework', 'test', 'foo', 'test_dump'];
        yield 'name, no debug' => [false, ['']$name];
        yield 'name, debug' => [true, ['']$name];

        


    /** * @dataProvider provideCompletionSuggestions */
    public function testComplete(array $input, array $expectedSuggestions)
    {
        $application = new Application();
        $application->add($this->createCommand($this->createMock(ProviderInterface::class)['en', 'fr', 'it']['messages', 'validators'], 'en', ['loco', 'crowdin', 'lokalise']));

        $tester = new CommandCompletionTester($application->get('translation:pull'));
        $suggestions = $tester->complete($input);
        $this->assertSame($expectedSuggestions$suggestions);
    }

    public static function provideCompletionSuggestions(): \Generator
    {
        yield 'provider' => [
            [''],
            ['loco', 'crowdin', 'lokalise'],
        ];

        yield '--domains' => [
            [
return is_numeric($statusCode) ? (int) $statusCode : 0;
    }

    /** * Adds suggestions to $suggestions for the current completion input (e.g. option or argument). */
    public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
    {
        $definition = $this->getDefinition();
        if (CompletionInput::TYPE_OPTION_VALUE === $input->getCompletionType() && $definition->hasOption($input->getCompletionName())) {
            $definition->getOption($input->getCompletionName())->complete($input$suggestions);
        } elseif (CompletionInput::TYPE_ARGUMENT_VALUE === $input->getCompletionType() && $definition->hasArgument($input->getCompletionName())) {
            $definition->getArgument($input->getCompletionName())->complete($input$suggestions);
        }
    }

    /** * Sets the code to execute when running this command. * * If this method is used, it overrides the code defined * in the execute() method. * * @param callable $code A callable(InputInterface $input, OutputInterface $output) * * @return $this * * @throws InvalidArgumentException * * @see execute() */

        $currentIndex = \count($input);
        if ('' === end($input)) {
            array_pop($input);
        }
        array_unshift($input$this->command->getName());

        $completionInput = CompletionInput::fromTokens($input$currentIndex);
        $completionInput->bind($this->command->getDefinition());
        $suggestions = new CompletionSuggestions();

        $this->command->complete($completionInput$suggestions);

        $options = [];
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $options[] = '--'.$option->getName();
        }

        return array_map('strval', array_merge($options$suggestions->getValueSuggestions()));
    }
}


    /** * @dataProvider provideCompletionSuggestions */
    public function testComplete(bool $debug, array $input, array $expectedSuggestions)
    {
        $application = $this->createApplication($debug);

        $application->add(new ConfigDumpReferenceCommand());
        $tester = new CommandCompletionTester($application->get('config:dump-reference'));
        $suggestions = $tester->complete($input);
        $this->assertSame($expectedSuggestions$suggestions);
    }

    public static function provideCompletionSuggestions(): iterable
    {
        $name = ['foo', 'default_config_test', 'extension_without_config_test', 'framework', 'test', 'test_dump', 'DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
        yield 'name, no debug' => [false, ['']$name];
        yield 'name, debug' => [true, ['']$name];

        $optionFormat = ['yaml', 'xml'];
        yield 'option --format, no debug' => [false, ['--format', '']$optionFormat];
        
'<info>Input:</> <comment>("|" indicates the cursor position)</>',
                ' '.(string) $completionInput,
                '<info>Command:</>',
                ' '.(string) implode(' ', $_SERVER['argv']),
                '<info>Messages:</>',
            ]);

            $command = $this->findCommand($completionInput$output);
            if (null === $command) {
                $this->log(' No command found, completing using the Application class.');

                $this->getApplication()->complete($completionInput$suggestions);
            } elseif (
                $completionInput->mustSuggestArgumentValuesFor('command')
                && $command->getName() !== $completionInput->getCompletionValue()
                && !\in_array($completionInput->getCompletionValue()$command->getAliases(), true)
            ) {
                $this->log(' No command found, completing using the Application class.');

                // expand shortcut names ("cache:cl<TAB>") into their full name ("cache:clear")                 $suggestions->suggestValues(array_filter(array_merge([$command->getName()]$command->getAliases())));
            } else {
                $command->mergeApplicationDefinition();
                
$globalFailureReceiverName => $receiver,
        ]);

        $command = new FailedMessagesRetryCommand(
            $globalFailureReceiverName,
            $serviceLocator,
            $this->createMock(MessageBusInterface::class),
            new EventDispatcher()
        );
        $tester = new CommandCompletionTester($command);

        $suggestions = $tester->complete(['--transport']);
        $this->assertSame(['global_receiver', 'failure_receiver']$suggestions);
    }

    public function testCompleteId()
    {
        $globalFailureReceiverName = 'failure_receiver';

        $receiver = $this->createMock(ListableReceiverInterface::class);
        $receiver->expects($this->once())->method('all')->with(50)->willReturn([
            Envelope::wrap(new \stdClass()[new TransportMessageIdStamp('2ab50dfa1fbf')]),
            Envelope::wrap(new \stdClass()[new TransportMessageIdStamp('78c2da843723')]),
        ]);
$tester->execute(['transport' => 'not_found']);
    }

    /** * @dataProvider provideCompletionSuggestions */
    public function testComplete(array $input, array $expectedSuggestions)
    {
        $serviceLocator = $this->createMock(ServiceLocator::class);
        $command = new SetupTransportsCommand($serviceLocator['amqp', 'other_transport']);
        $tester = new CommandCompletionTester($command);
        $suggestions = $tester->complete($input);
        $this->assertSame($expectedSuggestions$suggestions);
    }

    public static function provideCompletionSuggestions()
    {
        yield 'transport' => [['']['amqp', 'other_transport']];
    }
}

#[Package('checkout')] class RefundTestPaymentHandler implements RefundPaymentHandlerInterface
{
    public function __construct(private readonly OrderTransactionCaptureRefundStateHandler $stateHandler)
    {
    }

    public function refund(string $refundId, Context $context): void
    {
        $this->stateHandler->complete($refundId$context);
    }
}
'<info>Input:</> <comment>("|" indicates the cursor position)</>',
                ' '.(string) $completionInput,
                '<info>Command:</>',
                ' '.(string) implode(' ', $_SERVER['argv']),
                '<info>Messages:</>',
            ]);

            $command = $this->findCommand($completionInput$output);
            if (null === $command) {
                $this->log(' No command found, completing using the Application class.');

                $this->getApplication()->complete($completionInput$suggestions);
            } elseif (
                $completionInput->mustSuggestArgumentValuesFor('command')
                && $command->getName() !== $completionInput->getCompletionValue()
                && !\in_array($completionInput->getCompletionValue()$command->getAliases(), true)
            ) {
                $this->log(' No command found, completing using the Application class.');

                // expand shortcut names ("cache:cl<TAB>") into their full name ("cache:clear")                 $suggestions->suggestValues(array_filter(array_merge([$command->getName()]$command->getAliases())));
            } else {
                $command->mergeApplicationDefinition();
                


    /** * @dataProvider provideCompletionSuggestions */
    public function testComplete(array $input, array $expectedSuggestions)
    {
        require_once realpath(__DIR__.'/../Fixtures/FooCommand.php');
        $application = new Application();
        $application->add(new \FooCommand());
        $tester = new CommandCompletionTester($application->get('help'));
        $suggestions = $tester->complete($input, 2);
        $this->assertSame($expectedSuggestions$suggestions);
    }

    public static function provideCompletionSuggestions()
    {
        yield 'option --format' => [
            ['--format', ''],
            ['txt', 'xml', 'json', 'md', 'rst'],
        ];

        yield 'nothing' => [
            [

        $currentIndex = \count($input);
        if ('' === end($input)) {
            array_pop($input);
        }
        array_unshift($input$this->command->getName());

        $completionInput = CompletionInput::fromTokens($input$currentIndex);
        $completionInput->bind($this->command->getDefinition());
        $suggestions = new CompletionSuggestions();

        $this->command->complete($completionInput$suggestions);

        $options = [];
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $options[] = '--'.$option->getName();
        }

        return array_map('strval', array_merge($options$suggestions->getValueSuggestions()));
    }
}


    /** * @dataProvider provideCompletionSuggestions */
    public function testComplete(array $input, array $expectedSuggestions)
    {
        $application = new Application();
        $application->add($this->createCommand($this->createMock(ProviderInterface::class)['en', 'fr', 'it']['messages', 'validators']['loco', 'crowdin', 'lokalise']));

        $tester = new CommandCompletionTester($application->get('translation:push'));
        $suggestions = $tester->complete($input);
        $this->assertSame($expectedSuggestions$suggestions);
    }

    public static function provideCompletionSuggestions(): \Generator
    {
        yield 'provider' => [
            [''],
            ['loco', 'crowdin', 'lokalise'],
        ];

        yield '--domains' => [
            [
$serviceLocator->expects($this->once())->method('getProvidedServices')->willReturn([
            'global_receiver' => $receiver,
            $globalFailureReceiverName => $receiver,
        ]);

        $command = new FailedMessagesRemoveCommand(
            $globalFailureReceiverName,
            $serviceLocator
        );
        $tester = new CommandCompletionTester($command);

        $suggestions = $tester->complete(['--transport']);
        $this->assertSame(['global_receiver', 'failure_receiver']$suggestions);
    }

    public function testCompleteId()
    {
        $globalFailureReceiverName = 'failure_receiver';

        $receiver = $this->createMock(ListableReceiverInterface::class);
        $receiver->expects($this->once())->method('all')->with(50)->willReturn([
            Envelope::wrap(new \stdClass()[new TransportMessageIdStamp('2ab50dfa1fbf')]),
            Envelope::wrap(new \stdClass()[new TransportMessageIdStamp('78c2da843723')]),
        ]);

    private Filesystem $fs;
    private string $translationDir;

    /** * @dataProvider provideCompletionSuggestions */
    public function testComplete(array $input, array $expectedSuggestions)
    {
        $tester = $this->createCommandCompletionTester(['messages' => ['foo' => 'foo']]);

        $suggestions = $tester->complete($input);

        $this->assertSame($expectedSuggestions$suggestions);
    }

    public static function provideCompletionSuggestions()
    {
        $bundle = new ExtensionPresentBundle();

        yield 'locale' => [['']['en', 'fr']];
        yield 'bundle' => [['en', ''][$bundle->getName()$bundle->getContainerExtension()->getAlias()]];
        yield 'domain with locale' => [['en', '--domain=m']['messages']];
        
Home | Imprint | This part of the site doesn't use cookies.