-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Console ApplicationTester does not allow multiple prompts on invalid Question input #37046
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
Comments
Due to a bug in symfony/console v5 releases (symfony/symfony#37046), when specifying multiple inputs, only the first is used in test environments, which breaks tests that verify that questions re-prompt on invalid input. The solution is to set the max attempts to a reasonably high value during testing. I have accomplished that by setting an enviornment variable, which I then check for before asking the question. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Same as symfony/maker-bundle#629. I agree with the proposed solution. |
symfony/maker-bundle#629 is different and is going to be fixed by my patch suggestion on #37122 IIUC. Here, we're running into a conflict with #36590 I agree that the meaning of @ostrolucky WDYT? |
Problem here is that ApplicationTester uses php://memory as input stream and this is of course not considered to be a tty. Since we introduced QuestionHelper::isTty function only so we can prevent infinite loops (which shouldn't happen with ApplicationTester or via similar methods), I would think it would be fair enough to remove |
So, the first line of the For the application tester, this might mean that the behavior changes when running in a CI that exposes a TTY. Do they all do? What about Windows? |
#37160 should help answer this question |
…strolucky) This PR was merged into the 4.4 branch. Discussion ---------- Reset question validator attempts only for actual stdin | Q | A | ------------- | --- | Branch? | 4/4 | Bug fix? | yes | New feature? | no | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #37046 | License | MIT | Doc PR | Let's see what CI says. Works for me locally with phpunit and when running such command manually Commits ------- 8fe7be4 Reset question validator attempts only for actual stdin
symfony/console 5.1.2 incorporates symfony/symfony#37160, which fixes symfony/symfony#37046, removing the need for the workarounds introduced in TypeHintedParamAwareInput. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Symfony version(s) affected: 5.0.0, 5.1.0
Description
When using the
QuestionHelper
and testing via anApplicationTester
, if$maxAttempts
has not been set, the question will stop prompting for input after the first question response, regardless of whether or not more input are available.How to reproduce
Expected result:
Actual result:
Possible Solution
In both version 4 and version 5 code,
QuestionHelper::validateAttempts()
has the following loop defined:In version 5, the following line is added at the end of the loop:
This means that you will always run the loop exactly 1 time when
$attempts
is set tonull
, asisTty()
always returnsfalse
when run under theApplicationTester
(which uses a PHP memory stream to represent the TTY input stream).An
$attempts
value ofnull
is meant to indicate no maximum, and to prompt indefinitely; more importantly, it is the default value.In order to preserve previous (and documented) behavior, I think this should likely read:
The text was updated successfully, but these errors were encountered: