Symfony 交互式命令测试以 RuntimeException 结束

Symfony interactive Command Test ends with RuntimeException

我正在尝试使用交互式输入测试我的控制台命令。所以我写了一个函数来改变问题助手的输入流。

protected function getInputStream($input)
{
    $stream = fopen('php://memory', 'r+', false);
    fwrite($stream, $input);
    rewind($stream);

    return $stream;
}

这是我失败的代码

public function testRunCommandWithoutArguments()
{
    self::bootKernel();
    $application = new Application(self::$kernel);
    $application->setAutoExit(false);
    $application->add(new InstallCommand());

    $command = $application->find('app:install');
    $commandTester = new CommandTester($command);
    $helper = $command->getHelper('question');
    /** @var QuestionHelper $helper */
    $helper->setInputStream($this->getInputStream('No\nNo\n'));

    $commandTester->execute(array('command' => $command->getName()));
}

RuntimeException : Aborted /Users/Ashura/Documents/Projects/CustomFramework/vendor/symfony/symfony/src/Symfony/Component/Console/Helper/QuestionHelper.php:135 /Users/Ashura/Documents/Projects/CustomFramework/vendor/symfony/symfony/src/Symfony/Component/Console/Helper/QuestionHelper.php:56 /Users/Ashura/Documents/Projects/CustomFramework/src/AppBundle/Command/InstallCommand.php:96 /Users/Ashura/Documents/Projects/CustomFramework/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256 /Users/Ashura/Documents/Projects/CustomFramework/vendor/symfony/symfony/src/Symfony/Component/Console/Tester/CommandTester.php:80 /Users/Ashura/Documents/Projects/CustomFramework/tests/AppBundle/Command/InstallCommandTest.php:79

\n 单引号不起作用,它们显示在 print 例如。

'No\nNo\n' 更改为 "No\nNo\n" 应该可以。

另一个我比较喜欢的:sprintf('No%1$sNo%1$s', PHP_EOL)