I have a Symfony console command configured as below:
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
)
;
}
...and I have a PHPUnit test for it which looks like this:
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'
]);
}
When I run it I get the following error:
InvalidArgumentException: The "filepath" argument does not exist.
My question is - how do I pass through an Option to the CommandTester
? Passing arguments is fine, but I can't find docs on how to do it for Options.
You should pass the options with --
so try this:
$commandTester->execute([
'command' => $command->getName(),
'--filepath' => '/tmp/crmpicco.co.uk.csv'
]);
instead of this:
$commandTester->execute([
'command' => $command->getName(),
'filepath' => '/tmp/crmpicco.co.uk.csv'
]);
Hope this help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With