Skip to content
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

Merged
merged 1 commit into from
Jun 30, 2016

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented May 28, 2016

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.

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:
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Contributor

LGTM 👍

@chalasr
Copy link
Member Author

chalasr commented Jun 2, 2016

Updated according to symfony/symfony@19117ce
Tests pass

@chalasr chalasr force-pushed the commandtester_userinputs branch from 8af5ff0 to 0d03e8a Compare June 4, 2016 10:43
@chalasr chalasr force-pushed the commandtester_userinputs branch from 0d03e8a to a8e793a Compare June 16, 2016 11:00
fabpot added a commit to symfony/symfony that referenced this pull request Jun 16, 2016
…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
symfony-splitter pushed a commit to symfony/console that referenced this pull request Jun 16, 2016
…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
@chalasr
Copy link
Member Author

chalasr commented Jun 16, 2016

This is no more on hold, the PR has been merged.

@javiereguiluz
Copy link
Member

Status: needs review

@chalasr
Copy link
Member Author

chalasr commented Jun 16, 2016

Thank you @javiereguiluz, can I do it myself for next?

@javiereguiluz
Copy link
Member

@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"

@chalasr chalasr force-pushed the commandtester_userinputs branch from a8e793a to 096308f Compare June 16, 2016 17:39
@xabbuh xabbuh removed the On hold label Jun 18, 2016
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.
Copy link
Member

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?).

Copy link
Member Author

@chalasr chalasr Jun 18, 2016

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.

@chalasr chalasr force-pushed the commandtester_userinputs branch from 51eb9d0 to b50ab55 Compare June 18, 2016 10:34
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
Copy link
Member

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
Copy link
Member

wouterj commented Jun 19, 2016

Thanks for the contribution @chalasr! I've added 2 not so big comments.

Status: needs work

@chalasr chalasr force-pushed the commandtester_userinputs branch 5 times, most recently from bc90258 to b56ad94 Compare June 19, 2016 10:52
@chalasr
Copy link
Member Author

chalasr commented Jun 19, 2016

@wouterj I made the changes.

Status: needs review

@chalasr chalasr force-pushed the commandtester_userinputs branch 4 times, most recently from f2bcdfc to e9218b3 Compare June 20, 2016 19:14
@chalasr
Copy link
Member Author

chalasr commented Jun 20, 2016

I made some changes.
Do not hesitate to give me your suggestions, writing documentation is almost harder than adding the feature itself!

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');
Copy link
Member

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.

@chalasr
Copy link
Member Author

chalasr commented Jun 22, 2016

@wouterj Changes made, thanks for the review.

@wouterj
Copy link
Member

wouterj commented Jun 22, 2016

Status: reviewed

👍 thanks for the contribution!

@chalasr chalasr force-pushed the commandtester_userinputs branch 3 times, most recently from fa056e2 to eaa3294 Compare June 23, 2016 18:28
@chalasr
Copy link
Member Author

chalasr commented Jun 23, 2016

@javiereguiluz Please let me know if it is complete enough for you.

@chalasr chalasr force-pushed the commandtester_userinputs branch from eaa3294 to 0694d58 Compare June 23, 2016 18:34
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
@chalasr chalasr force-pushed the commandtester_userinputs branch from 0694d58 to 26fdbe0 Compare June 23, 2016 18:46
@javiereguiluz
Copy link
Member

👍

@chalasr thanks for providing these docs and for your patience during the review process.

@xabbuh
Copy link
Member

xabbuh commented Jun 30, 2016

Thank you @chalasr.

@xabbuh xabbuh merged commit 26fdbe0 into symfony:master Jun 30, 2016
xabbuh added a commit that referenced this pull request Jun 30, 2016
…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
xabbuh added a commit that referenced this pull request Jun 30, 2016
@chalasr chalasr deleted the commandtester_userinputs branch June 30, 2016 17:02
@chalasr chalasr restored the commandtester_userinputs branch August 16, 2016 12:02
@chalasr chalasr deleted the commandtester_userinputs branch October 25, 2016 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants