【发布时间】:2017-03-02 02:42:03
【问题描述】:
我有一个 Symfony 控制台命令配置如下:
protected function configure()
{
$this
->setName('crmpiccobundle:list:sync')
->setDescription('Sync users to the list')
->addOption(
'filepath',
null,
InputOption::VALUE_OPTIONAL,
'The path to the file',
null
)
;
}
...我有一个 PHPUnit 测试,看起来像这样:
public function testExecuteWhenFileIsEmpty()
{
self::bootKernel();
$application = new Application(self::$kernel);
$application->add(new Sync());
$command = $application->find('crmpiccobundle:list:sync');
$commandTester = new CommandTester($command);
$commandTester->execute([
'command' => $command->getName(),
'filepath' => '/tmp/crmpicco.co.uk.csv'
]);
}
当我运行它时,我收到以下错误:
InvalidArgumentException:“文件路径”参数不存在。
我的问题是 - 我如何通过 Option 到 CommandTester?传递参数很好,但我找不到关于如何为 Options 做的文档。
【问题讨论】:
-
你试过
'--filepath' => '/tmp/crmpicco.co.uk.csv'吗? -
@Matteo 谢谢,这就是答案。请随时提交,我很乐意接受。干杯。
标签: php unit-testing symfony phpunit php-7