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

Commitc1570dc

Browse files
committed
[Console] Test SymfonyStyle::ask() output
1 parentafed2f8 commitc1570dc

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+
useSymfony\Component\Console\Input\InputInterface;
4+
useSymfony\Component\Console\Output\OutputInterface;
5+
useSymfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
//Ensure that questions have the expected outputs
8+
returnfunction (InputInterface$input,OutputInterface$output) {
9+
$output =newSymfonyStyleWithForcedLineLength($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+
publicfunctiontestInteractiveOutputs($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+
publicfunctioninputInteractiveCommandToOutputFilesProvider()
63+
{
64+
$baseDir =__DIR__.'/../Fixtures/Style/SymfonyStyle';
65+
66+
returnarray_map(null,glob($baseDir.'/command/interactive_command_*.php'),glob($baseDir.'/output/interactive_output_*.txt'));
67+
}
68+
5169
publicfunctioninputCommandToOutputFilesProvider()
5270
{
5371
$baseDir =__DIR__.'/../Fixtures/Style/SymfonyStyle';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp