Php Laravel/Symfony-如何在控制台命令中测试确认?

Php Laravel/Symfony-如何在控制台命令中测试确认?,php,unit-testing,symfony,laravel,laravel-4,Php,Unit Testing,Symfony,Laravel,Laravel 4,我知道我可以通过如下方式传递参数和选项来单元测试控制台命令: $command->run(new ArrayInput($data), new NullOutput); 但是,如果我想通过使用向命令中添加确认对话框,该怎么办?您在Symfony的网站上看过这个示例了吗 如果您在使其工作时遇到了问题,请告诉我们。我忘了提到我在单元测试中使用了PHPSpec 最后我想出了如何用它来测试确认 以下是use语句: use PhpSpec\ObjectBehavior; use Prophecy

我知道我可以通过如下方式传递参数和选项来单元测试控制台命令:

$command->run(new ArrayInput($data), new NullOutput);

但是,如果我想通过使用向命令中添加确认对话框,该怎么办?

您在Symfony的网站上看过这个示例了吗


如果您在使其工作时遇到了问题,请告诉我们。

我忘了提到我在单元测试中使用了PHPSpec

最后我想出了如何用它来测试确认

以下是
use
语句:

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Helper\HelperSet;
这是一个样本测试:

public function it_fires_the_command(QuestionHelper $question, HelperSet $helpers)
{
    // $data is an array containing arguments and options for the console command
    $input = new ArrayInput($data);

    $output = new NullOutput;

    // $query must be an instance of ConfirmationQuestion
    $query = Argument::type('Symfony\Component\Console\Question\ConfirmationQuestion');

    // with "willReturn" we can decide whether (TRUE) or not (FALSE) the user confirms
    $question->ask($input, $output, $query)->willReturn(true);

    // we expect the HelperSet to be invoked returning the mocked QuestionHelper
    $helpers->get('question')->willReturn($question);

    // finally we set the mocked HelperSet in our console command...
    $this->setHelperSet($helpers);

    // ...and run it
    $this->run($input, $output);
}

哦,我错过了!非常感谢您提供的链接,找到解决方案至关重要:)@AndreaMarcoSartori您能将此答案标记为解决方案吗?