Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure final input of CommandTester works with default #29754

Merged
merged 1 commit into from Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Symfony/Component/Console/Tester/CommandTester.php
Expand Up @@ -148,7 +148,10 @@ private static function createStream(array $inputs)
{
$stream = fopen('php://memory', 'r+', false);

fwrite($stream, implode(PHP_EOL, $inputs));
foreach ($inputs as $input) {
fwrite($stream, $input.PHP_EOL);
}

rewind($stream);

return $stream;
Expand Down
25 changes: 25 additions & 0 deletions src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php
Expand Up @@ -112,6 +112,31 @@ public function testCommandWithInputs()
$this->assertEquals(implode('', $questions), $tester->getDisplay(true));
}

public function testCommandWithDefaultInputs()
{
$questions = array(
'What\'s your name?',
'How are you?',
'Where do you come from?',
);

$command = new Command('foo');
$command->setHelperSet(new HelperSet(array(new QuestionHelper())));
$command->setCode(function ($input, $output) use ($questions, $command) {
$helper = $command->getHelper('question');
$helper->ask($input, $output, new Question($questions[0], 'Bobby'));
$helper->ask($input, $output, new Question($questions[1], 'Fine'));
$helper->ask($input, $output, new Question($questions[2], 'France'));
});

$tester = new CommandTester($command);
$tester->setInputs(array('', '', ''));
$tester->execute(array());

$this->assertEquals(0, $tester->getStatusCode());
$this->assertEquals(implode('', $questions), $tester->getDisplay(true));
}

/**
* @expectedException \RuntimeException
* @expectedMessage Aborted
Expand Down