CompletionInput example

$this->expectExceptionMessage('A default value for an array argument must be an array.');
        $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
        $argument->setDefault('default');
    }

    public function testCompleteArray()
    {
        $values = ['foo', 'bar'];
        $argument = new InputArgument('foo', null, '', null, $values);
        $this->assertTrue($argument->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $argument->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }

    public function testCompleteClosure()
    {
        $values = ['foo', 'bar'];
        $argument = new InputArgument('foo', null, '', null, fn (CompletionInput $input): array => $values);
        $this->assertTrue($argument->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $argument->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }
$this->expectExceptionMessage('Cannot set suggested values if the option does not accept a value.');

        new InputOption('foo', null, InputOption::VALUE_NONE, '', null, ['foo']);
    }

    public function testCompleteArray()
    {
        $values = ['foo', 'bar'];
        $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, $values);
        $this->assertTrue($option->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $option->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }

    public function testCompleteClosure()
    {
        $values = ['foo', 'bar'];
        $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, fn (CompletionInput $input): array => $values);
        $this->assertTrue($option->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $option->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }
Home | Imprint | This part of the site doesn't use cookies.