8000 minor #19097 [Console] Test SymfonyStyle::ask() output (chalasr) · symfony/symfony@88cf87e · GitHub
[go: up one dir, main page]

Skip to content

Commit 88cf87e

Browse files
committed
minor #19097 [Console] Test SymfonyStyle::ask() output (chalasr)
This PR was merged into the 3.2-dev branch. Discussion ---------- [Console] Test SymfonyStyle::ask() output | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Now that we can test an interactive command that uses SymfonyStyle (after #18999), we should test their output. Commits ------- e870758 [Console] Test SymfonyStyle::ask() output
2 parents 414a4b4 + e870758 commit 88cf87e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
$stream = fopen('php://memory', 'r+', false);
11+
12+
fputs($stream, "Foo\nBar\nBaz");
13+
rewind($stream);
14+
$input->setStream($stream);
15+
16+
$output->ask('What\'s your name?');
17+
$output->ask('How are you?');
18+
$output->ask('Where do you come from?');
19+
};
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
@@ -48,6 +48,24 @@ public function testOutputs($inputCommandFilepath, $outputFilepath)
4848
$this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
4949
}
5050

51+
/**
52+
* @dataProvider inputInteractiveCommandToOutputFilesProvider
53+
*/
54+
public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath)
55+
{
56+
$code = require $inputCommandFilepath;
57+
$this->command->setCode($code);
58+
$this->tester->execute(array(), array('interactive' => true, 'decorated' => false));
59+
$this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
60+
}
61+
62+
public function inputInteractiveCommandToOutputFilesProvider()
63+
{
64+
$baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
65+
66+
return array_map(null, glob($baseDir.'/command/interactive_command_*.php'), glob($baseDir.'/output/interactive_output_*.txt'));
67+
}
68+
5169
public function inputCommandToOutputFilesProvider()
5270
{
5371
$baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';

0 commit comments

Comments
 (0)
0