2016-10-20 149 views
1

我有如下配置一個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: The "filepath" argument does not exist.

我的問題是 - 如何傳遞救援人員到場唉一個選項CommandTester?傳遞參數很好,但我找不到有關如何爲選項執行操作的文檔。

+1

有你' '--filepath' 嘗試= >'/ tmp/crmpicco.co.uk.csv''? – Matteo

+1

@Matteo謝謝,這就是答案。請隨時提交,我會很樂意接受。乾杯。 – crmpicco

回答

1

您應該通過選擇與--所以試試這個:

$commandTester->execute([ 
    'command' => $command->getName(), 
    '--filepath' => '/tmp/crmpicco.co.uk.csv' 
]); 

,而不是這樣的:

$commandTester->execute([ 
    'command' => $command->getName(), 
    'filepath' => '/tmp/crmpicco.co.uk.csv' 
]); 

希望這有助於