-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
[Console] Adapt doc for easier testing of commands needing user inputs #6623
Conversation
If you want to write a unit test for a command which expects some kind of input | ||
from the command line, you need to set the helper input stream:: | ||
If you want to write a unit test for a command which expects user inputs | ||
from the command line, you need to set the inputs 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
LGTM 👍 |
Updated according to symfony/symfony@19117ce |
8af5ff0
to
0d03e8a
Compare
0d03e8a
to
a8e793a
Compare
…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#6623 After @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 #18999 Commits ------- 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#6623 After @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 #18999 Commits ------- c7ba38a [Console] Set user inputs from CommandTester
This is no more on hold, the PR has been merged. |
Status: needs review |
Thank you @javiereguiluz, can I do it myself for next? |
@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
to
096308f
Compare
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 the QuestionHelper
reads the stream when ask()
is called (via fgets
).
I added a short explanation, I hope it is clear enough.
51eb9d0
to
b50ab55
Compare
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
Thanks for the contribution @chalasr! I've added 2 not so big comments. Status: needs work |
bc90258
to
b56ad94
Compare
@wouterj I made the changes. Status: needs review |
f2bcdfc
to
e9218b3
Compare
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 be array('This', 'That')
(same on line 299).
Also, I think we should add the descriptive comment before the line of code.
@wouterj Changes made, thanks for the review. |
Status: reviewed 👍 thanks for the contribution! |
fa056e2
to
eaa3294
Compare
@javiereguiluz Please let me know if it is complete enough for you. |
eaa3294
to
0694d58
Compare
Fix missing colon Change userInputs to inputs Try to fix platformsh build Re-add useful use statements Fixed typo, use FQCN::method Rollback not useful diff Formatting Add more examples, precise documentation typo 'would have type' => 'would have typed' removing an ending dot in comment for consistency
0694d58
to
26fdbe0
Compare
👍 @chalasr thanks for providing these docs and for your patience during the review process. |
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 inputs Doc-PR for symfony/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
Doc-PR for symfony/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.