setAutocompleterValues example


    public function __construct(string $question, array $choices, mixed $default = null)
    {
        if (!$choices) {
            throw new \LogicException('Choice question must have at least 1 choice available.');
        }

        parent::__construct($question$default);

        $this->choices = $choices;
        $this->setValidator($this->getDefaultValidator());
        $this->setAutocompleterValues($choices);
    }

    /** * Returns available choices. */
    public function getChoices(): array
    {
        return $this->choices;
    }

    /** * Sets multiselect option. * * When multiselect is set to true, multiple choices can be answered. * * @return $this */
        // <DOWN ARROW><NEWLINE>         // S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>         // F00<BACKSPACE><BACKSPACE>oo<TAB><NEWLINE>         // F⭐<TAB><BACKSPACE><BACKSPACE>⭐<TAB><NEWLINE>         $inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\nF⭐\t\177\177⭐\t\n");

        $dialog = new QuestionHelper();
        $helperSet = new HelperSet([new FormatterHelper()]);
        $dialog->setHelperSet($helperSet);

        $question = new Question('Please select a bundle', 'FrameworkBundle');
        $question->setAutocompleterValues(['AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle', 'F⭐Y']);

        $this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('AsseticBundleTest', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('FrameworkBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('SecurityBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('FooBundleTest', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('AsseticBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('F⭐Y', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
    }

    

    public function __construct(string $question, array $choices, mixed $default = null)
    {
        if (!$choices) {
            throw new \LogicException('Choice question must have at least 1 choice available.');
        }

        parent::__construct($question$default);

        $this->choices = $choices;
        $this->setValidator($this->getDefaultValidator());
        $this->setAutocompleterValues($choices);
    }

    /** * Returns available choices. */
    public function getChoices(): array
    {
        return $this->choices;
    }

    /** * Sets multiselect option. * * When multiselect is set to true, multiple choices can be answered. * * @return $this */
'a', 'b', 'c', 'd'],
            ],
            'null' => [null, null],
        ];
    }

    /** * @dataProvider providerGetSetAutocompleterValues */
    public function testGetSetAutocompleterValues($values$expectValues)
    {
        $this->question->setAutocompleterValues($values);
        self::assertSame(
            $expectValues,
            $this->question->getAutocompleterValues()
        );
    }

    public static function providerSetAutocompleterValuesInvalid()
    {
        return [
            ['Potato'],
            [new \stdClass()],
            [
Home | Imprint | This part of the site doesn't use cookies.