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

Commitb645c07

Browse files
author
Robin Chalas
committed
bug#29754 Ensure final input of CommandTester works with default (Firehed)
This PR was merged into the 3.4 branch.Discussion----------Ensure final input of CommandTester works with default| Q | A| ------------- | ---| Branch? | 4.x| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -If the final element of `CommandTester::setInputs()` is an empty string (to send the default value), the internal stream the tester uses hits EOF and triggers the `Aborted` exception. This appends an additional EOL to the stream after the `implode` to simulate one final return key, allowing the final input to use the default value when used in the tester's documented style.A test has been added to cover the new behavior, which failed before this change.Commits-------6b87b67 Ensure final input of CommandTester works with default
2 parents44bb346 +6b87b67 commitb645c07

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

‎src/Symfony/Component/Console/Tester/CommandTester.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ private static function createStream(array $inputs)
148148
{
149149
$stream =fopen('php://memory','r+',false);
150150

151-
fwrite($stream,implode(PHP_EOL,$inputs));
151+
foreach ($inputsas$input) {
152+
fwrite($stream,$input.PHP_EOL);
153+
}
154+
152155
rewind($stream);
153156

154157
return$stream;

‎src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ public function testCommandWithInputs()
112112
$this->assertEquals(implode('',$questions),$tester->getDisplay(true));
113113
}
114114

115+
publicfunctiontestCommandWithDefaultInputs()
116+
{
117+
$questions =array(
118+
'What\'s your name?',
119+
'How are you?',
120+
'Where do you come from?',
121+
);
122+
123+
$command =newCommand('foo');
124+
$command->setHelperSet(newHelperSet(array(newQuestionHelper())));
125+
$command->setCode(function ($input,$output)use ($questions,$command) {
126+
$helper =$command->getHelper('question');
127+
$helper->ask($input,$output,newQuestion($questions[0],'Bobby'));
128+
$helper->ask($input,$output,newQuestion($questions[1],'Fine'));
129+
$helper->ask($input,$output,newQuestion($questions[2],'France'));
130+
});
131+
132+
$tester =newCommandTester($command);
133+
$tester->setInputs(array('','',''));
134+
$tester->execute(array());
135+
136+
$this->assertEquals(0,$tester->getStatusCode());
137+
$this->assertEquals(implode('',$questions),$tester->getDisplay(true));
138+
}
139+
115140
/**
116141
* @expectedException \RuntimeException
117142
* @expectedMessage Aborted

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp