diff --git a/src/Symfony/Component/Console/Tester/CommandTester.php b/src/Symfony/Component/Console/Tester/CommandTester.php index 131ca9b160e9..c2d18fa28843 100644 --- a/src/Symfony/Component/Console/Tester/CommandTester.php +++ b/src/Symfony/Component/Console/Tester/CommandTester.php @@ -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; diff --git a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php index 58eb8103fcc9..da5f2e7aed03 100644 --- a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php +++ b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php @@ -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