首页 > 解决方案 > 我的命令如何通过可选参数传递给另一个 Artisan 命令?

问题描述

(更新的问题表明它不像链接的问题)

我编写了一个 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')]);
    }

}

如您所见,我已经阅读了这些文档并了解如何编写$signature以接受可选参数。

我的目标是有时能够运行php artisan mydusk,并且还能够有选择地添加参数,例如当我可能想要调用类似的东西时php artisan mydusk tests/Browser/MailcheckTest.php --filter testBasicValidCaseButtonClick(这会将tests/Browser/MailcheckTest.php --filter testBasicValidCaseButtonClick参数传递给普通dusk命令)。

如何编辑handle()函数的最后两行以便$file传递给dusk

标签: laravellaravel-5laravel-artisanlaravel-dusk

解决方案


您也可以查看这些链接,它可能会对您有所帮助。

堆栈答案 1

堆栈答案 2


推荐阅读