我写了一个Laravel命令(完整显示在下面),它基本上是Dusk的包装,因此我可以确保事先调用某些其他函数。 (否则,我不可避免地会忘记重置测试环境。)
当我运行php artisan mydusk
时,它运行完美。
namespace App\Console\Commands;
class DuskCommand extends BaseCommand {
protected $signature = 'mydusk {file?} {--filter=?}';
protected $description = 'refreshAndSeedTestingDb, then run Dusk suite of tests';
public function handle() {
$this->consoleOutput($this->description);
$resetTestingEnv = new ResetTestingEnv();
$resetTestingEnv->refreshAndSeedTestingDb();
$this->consoleOutput('refreshAndSeedTestingDb finished. Now will run Dusk...');
$file = $this->argument('file');//What to do with this?
return \Artisan::call('dusk', ['--filter' => $this->option('filter')]);
}
}
如您所见,我已经读过these docs,并且了解如何编写$signature
来接受可选参数。
我的目标是有时可以运行php artisan mydusk
,还可以有选择地添加参数,例如当我可能想调用类似php artisan mydusk tests/Browser/MailcheckTest.php --filter testBasicValidCaseButtonClick
的东西时(它将传递tests/Browser/MailcheckTest.php --filter testBasicValidCaseButtonClick
参数传递给普通的dusk
命令。
如何编辑handle()
函数的最后两行,以便将$file
传递给dusk
?
答案 0 :(得分:0)
答案 1 :(得分:0)
最初,我确实误会了您的问题。但是,文档中还有一节概述了how to programatically call an Artisan command。
根据您的问题,我假设您不确定如何传递file
参数,因为可以说,当作为命令调用时,没有key
。
php artisan mydusk {file?} {--filter=}
以下内容来自Laravel文档。 key
参数的file
应该是参数的名称。至于参数是可选的,如果在调用file
命令时未指定mydusk
参数,则null
将传递给dusk
命令。>
public function handle() {
// ...
$file = $this->argument('file');
$filter = $this->option('filter');
return Artisan::call('dusk', [
'file' => $file,
'--filter' => $filter,
]);
}
答案 2 :(得分:0)
从实验中得知我的原始功能确实按预期工作,我感到很惊讶,并且可以删除惰性行(sns.countplot(x="loan_status", data=LoanStats_securev1_2018Q1, palette="Greens_d");
<matplotlib.axes._subplots.AxesSubplot at 0x993d455668>
)。
通过$file = $this->argument('file');
传递file
参数实际上似乎根本没有必要。
@fubar的回答似乎和我最初所做的错误假设相同。
@Jonas Staudenmeir在评论中暗示,Laravel\Dusk\Console\DuskCommand
使用来自\Artisan::call()
的参数。