Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Console] Adapt doc for easier testing of commands needing user inputs#6623
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| If you want to write a unit test for a command which expectssome kind of input | ||
| from the command line, you need to set thehelper input stream:: | ||
| If you want to write a unit test for a command which expectsuser inputs | ||
| from the command line, you need to set theinputs like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You need to end the paragraph with two colons so that the following block will be properly treated as a PHP code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Fixed, Thank's@xabbuh
OskarStark commentedJun 2, 2016
LGTM 👍 |
chalasr commentedJun 2, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Updated according tosymfony/symfony@19117ce |
8af5ff0 to0d03e8aCompare0d03e8a toa8e793aCompare…dTester (chalasr)This PR was merged into the 3.2-dev branch.Discussion----------[Console] Simplify simulation of user inputs in CommandTester| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR |symfony/symfony-docs#6623After@javiereguiluz pointed it in#17470, I open this PR to simplify the simulation of user inputs for testing a Command.It would be done by calling `CommandTester::setUserInputs()` with an array of inputs as argument, and so make the CommandTester creating an input stream from the inputs set by the developer, then call `QuestionHelper::setInputStream` and assign it to the helperSet of the command, sort as all is done automatically in one call.Depends on#18999Commits-------c7ba38a [Console] Set user inputs from CommandTester
…dTester (chalasr)This PR was merged into the 3.2-dev branch.Discussion----------[Console] Simplify simulation of user inputs in CommandTester| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR |symfony/symfony-docs#6623After@javiereguiluz pointed it in #17470, I open this PR to simplify the simulation of user inputs for testing a Command.It would be done by calling `CommandTester::setUserInputs()` with an array of inputs as argument, and so make the CommandTester creating an input stream from the inputs set by the developer, then call `QuestionHelper::setInputStream` and assign it to the helperSet of the command, sort as all is done automatically in one call.Depends on #18999Commits-------c7ba38a [Console] Set user inputs from CommandTester
chalasr commentedJun 16, 2016
This is no more on hold, the PR has been merged. |
javiereguiluz commentedJun 16, 2016
Status: needs review |
chalasr commentedJun 16, 2016
Thank you@javiereguiluz, can I do it myself for next? |
javiereguiluz commentedJun 16, 2016
@chalasr yes, it's explained a bit here:http://symfony.com/doc/current/contributing/community/reviews.html#the-bug-report-review-process Sadly our bot still has things to learn. I'd love to say:"hey Carson, remove the "On hold" label" |
a8e793a to096308fCompare| input stream. | ||
| By calling:method:`CommandTester::setInputs`, you imitate what the console would | ||
| do internally with all user input through the CLI. This way you can test any | ||
| user interaction (even complex ones) by passing the appropriate inputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think we should be more explicit what it means that the input is an array (IIUC one element is read once new input is requested by the command, right?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@xabbuh right, the behavior stays the same, we create a string from the given array of inputs, (each input is separated via a"\n"), then theQuestionHelper reads the stream whenask() is called (viafgets).
I addeda short explanation, I hope it is clear enough.
51eb9d0 tob50ab55Compare| console would do internally with all user input through the CLI. This way | ||
| you can test any user interaction (even complex ones) by passing an appropriate | ||
| input stream. | ||
| By calling:method:`CommandTester::setInputs`, you imitate what the console would |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this needs to be the FQCN
wouterj commentedJun 19, 2016
Thanks for the contribution@chalasr! I've added 2 not so big comments. Status: needs work |
bc90258 tob56ad94Comparechalasr commentedJun 19, 2016
@wouterj I made the changes. Status: needs review |
f2bcdfc toe9218b3Comparechalasr commentedJun 20, 2016
I made some changes. Status: needs review |
| // Equals to a user inputting "Test" and hitting ENTER | ||
| // If you need to enter a confirmation, "yes\n" will work | ||
| $commandTester->setInputs('This', 'That'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should bearray('This', 'That') (same on line 299).
Also, I think we should add the descriptive comment before the line of code.
chalasr commentedJun 22, 2016
@wouterj Changes made, thanks for the review. |
wouterj commentedJun 22, 2016
Status: reviewed 👍 thanks for the contribution! |
fa056e2 toeaa3294Comparechalasr commentedJun 23, 2016
@javiereguiluz Please let me know if it is complete enough for you. |
eaa3294 to0694d58CompareFix missing colonChange userInputs to inputsTry to fix platformsh buildRe-add useful use statementsFixed typo, use FQCN::methodRollback not useful diffFormattingAdd more examples, precise documentationtypo 'would have type' => 'would have typed'removing an ending dot in comment for consistency
0694d58 to26fdbe0Comparejaviereguiluz commentedJun 23, 2016
👍 @chalasr thanks for providing these docs and for your patience during the review process. |
xabbuh commentedJun 30, 2016
Thank you@chalasr. |
…ing user inputs (chalasr)This PR was merged into the master branch.Discussion----------[Console] Adapt doc for easier testing of commands needing user inputsDoc-PR forsymfony/symfony#18710.This one eases testing of commands needing user interactions by simulating them from the CommandTester directly, by creating a input stream from the ones set by the developer.Commits-------26fdbe0 [Console] Adapt doc for easier testing of commands needing user inputs
Uh oh!
There was an error while loading.Please reload this page.
Doc-PR forsymfony/symfony#18710.
This one eases testing of commands needing user interactions by simulating them from the CommandTester directly, by creating a input stream from the ones set by the developer.