8000 Test output of an interactive command with questions · symfony/symfony@d292651 · GitHub
[go: up one dir, main page]

Skip to content

Commit d292651

Browse files
committed
Test output of an interactive command with questions
1 parent 416efdf commit d292651

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
//Ensure that questions have the expected outputs
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
10+
$questions = array(
11+
'What\'s your name?',
12+
'How are you?',
13+
'Where do you come from?',
14+
);
15+
$inputs = ['Foo', 'Bar', 'Baz'];
16+
$stream = fopen('php://memory', 'r+', false);
17+
18+
fputs($stream, implode(PHP_EOL, $inputs));
19+
rewind($stream);
20+
$output->setInputStream($stream);
21+
22+
$output->ask($questions[0]);
23+
$output->ask($questions[1]);
24+
$output->ask($questions[2]);
25+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
What's your name?:
3+
>
4+
How are you?:
5+
>
6+
Where do you come from?:
7+
>

src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ public function inputCommandToOutputFilesProvider()
5555
return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
5656
}
5757

58+
/**
59+
* @dataProvider inputInteractiveCommandToOutputFilesProvider
60+
*/
61+
public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath)
62+
{
63+
$code = require $inputCommandFilepath;
64+
$this->command->setCode($code);
65+
$this->tester->execute(array());
66+
$this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
67+
}
68+
69+
public function inputInteractiveCommandToOutputFilesProvider()
70+
{
71+
$baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
72+
73+
return array_map(null, glob($baseDir.'/command/interactive_command_*.php'), glob($baseDir.'/output/interactive_output_*.txt'));
74+
}
75+
5876
public function testLongWordsBlockWrapping()
5977
{
6078
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygovgollhjvhvljfezefeqifzeiqgiqzhrsdgihqzridghqridghqirshdghdghieridgheirhsdgehrsdvhqrsidhqshdgihrsidvqhneriqsdvjzergetsrfhgrstsfhsetsfhesrhdgtesfhbzrtfbrztvetbsdfbrsdfbrn';

0 commit comments

Comments
 (0)
0