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

Commitbc90258

Browse files
committed
[Console] Adapt doc for easier testing of commands needing user inputs
Fix missing colonChange userInputs to inputsTry to fix platformsh buildRe-add useful use statementsFixed typo, use FQCN::methodRollback not useful diff
1 parenta01f87f commitbc90258

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

‎components/console/helpers/questionhelper.rst‎

Lines changed: 6 additions & 17 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 thehelper input stream::
280+
from the command line, you need to set theinputs like this::
281281

282282
use Symfony\Component\Console\Helper\QuestionHelper;
283283
use Symfony\Component\Console\Helper\HelperSet;
@@ -289,26 +289,15 @@ from the command line, you need to set the helper input stream::
289289
// ...
290290
$commandTester = new CommandTester($command);
291291

292-
$helper = $command->getHelper('question');
293-
$helper->setInputStream($this->getInputStream("Test\n"));
292+
$commandTester->setInputs(array('Test'));
294293
// Equals to a user inputting "Test" and hitting ENTER
295-
// If you need to enter a confirmation, "yes\n" will work
294+
// If you need to enter a confirmation,adding a second input saying"yes" will work
296295

297296
$commandTester->execute(array('command' => $command->getName()));
298297

299298
// $this->assertRegExp('/.../', $commandTester->getDisplay());
300299
}
301300

302-
protected function getInputStream($input)
303-
{
304-
$stream = fopen('php://memory', 'r+', false);
305-
fputs($stream, $input);
306-
rewind($stream);
307-
308-
return $stream;
309-
}
310-
311-
By setting the input stream of the ``QuestionHelper``, you imitate what the
312-
console would do internally with all user input through the CLI. This way
313-
you can test any user interaction (even complex ones) by passing an appropriate
314-
input stream.
301+
By calling:method:`Symfony\\Component\\Console\\Tester\\CommandTester::setInputs`, you imitate what the console would
302+
do internally with all user input through the CLI. This way you can test any
303+
user interaction (even complex ones) by passing the appropriate inputs.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp