Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf2bcdfc

Browse files
committed
Add more examples, precise documentation
1 parentb56ad94 commitf2bcdfc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎components/console/helpers/questionhelper.rst‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ Testing a Command that Expects Input
277277
------------------------------------
278278

279279
If you want to write a unit test for a command which expects some kind of input
280-
from the command line, you need to set the inputslike this::
280+
from the command line, you need to set the inputsthat the command expects::
281281

282282
use Symfony\Component\Console\Helper\QuestionHelper;
283283
use Symfony\Component\Console\Helper\HelperSet;
@@ -291,7 +291,14 @@ from the command line, you need to set the inputs like this::
291291

292292
$commandTester->setInputs(array('Test'));
293293
// Equals to a user inputting "Test" and hitting ENTER
294-
// If you need to enter a confirmation, adding an additional input saying "yes" will work
294+
295+
$commandTester->setInputs('This', 'That');
296+
// Equals to a user inputting "This", "That" and hitting ENTER
297+
// This can be used for answering two separated questions for instance.
298+
299+
$commandTester->setInputs('This', 'That', 'yes');
300+
// For simulating a positive answer to a confirmation question, adding an
301+
// additional input saying "yes" will work
295302

296303
$commandTester->execute(array('command' => $command->getName()));
297304

@@ -300,4 +307,10 @@ from the command line, you need to set the inputs like this::
300307

301308
By calling:method:`Symfony\\Component\\Console\\Tester\\CommandTester::setInputs`,
302309
you imitate what the console would do internally with all user input through the CLI.
310+
This method takes an array as only argument with, for each input that the command expects,
311+
a string representing what the user would have type.
303312
This way you can test any user interaction (even complex ones) by passing the appropriate inputs.
313+
314+
..note::
315+
The:class:`Symfony\Component\Console\Tester\CommandTester` automatically simulates a user hitting
316+
``ENTER`` after each input, no need for passing an additional input.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp