Skip to content

[Console] Make SymfonyQuestionHelper::ask optional by default #22317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-3.4.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
UPGRADE FROM 3.3 to 3.4
=======================

Console
-------

* Default validation in `SymfonyQuestionHelper::ask` has been deprecated and will be removed in 4.0. Apply validation using `Question::setValidator` instead.

DependencyInjection
-------------------

Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Console
* The `console.exception` event and the related `ConsoleExceptionEvent` class have
been removed in favor of the `console.error` event and the `ConsoleErrorEvent` class.

* Default validation in `SymfonyQuestionHelper::ask` has been removed in favor of `Question::setValidator`.

Debug
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'You can either install it or use the "server:run" command instead.',
));

if ($io->ask('Do you want to execute <info>server:run</info> immediately? [yN] ', false)) {
if ($io->confirm('Do you want to execute <info>server:run</info> immediately?', false)) {
return $this->getApplication()->find('server:run')->run($input, $output);
}

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CHANGELOG
* deprecated console.exception event in favor of console.error
* added ability to handle `CommandNotFoundException` through the
`console.error` event
* deprecated default validation in `SymfonyQuestionHelper::ask`

3.2.0
------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class SymfonyQuestionHelper extends QuestionHelper
{
/**
* {@inheritdoc}
*
* BC to be removed in 4.0
*/
public function ask(InputInterface $input, OutputInterface $output, Question $question)
{
Expand All @@ -39,6 +41,8 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
} else {
// make required
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
@trigger_error('The default question validator is deprecated since Symfony 3.4 and will not be used anymore in version 4.0. Set a custom question validator instead.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ro0NL is this really in the correct code path? Throwing both a deprecation and an exception is suspicious to me.

Copy link
Member

@chalasr chalasr Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed

Copy link
Contributor Author

@ro0NL ro0NL Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're deprecating the fact this exception is thrown when the value is blank. Meaning in 4.0 ask() is optional by default, whereas now it's required by default.

I actually considered putting the trigger above if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {, but its weird to get the deprecation for a case that is still valid in 4.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I think it's the right place for this deprecation.


throw new LogicException('A value is required.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ public function testAskThrowsExceptionOnMissingInput()
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?'));
}

/**
* @group legacy
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
* @expectedExceptionMessage Aborted
* @expectedDeprecation The default question validator is deprecated since Symfony 3.4 and will not be used anymore in version 4.0. Set a custom question validator instead.
*/
public function testLegacyAsk()
{
$dialog = new SymfonyQuestionHelper();
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream(' ')), $this->createOutputInterface(), new Question('Question'));
}

protected function getInputStream($input)
{
$stream = fopen('php://memory', 'r+', false);
Expand Down