dimanche 1 juillet 2018

How can my command accept optional arguments and pass along to Artisan?

I wrote a Laravel command (shown in its entirety below) that basically is a wrapper for Dusk so that I can be sure to call certain other functions beforehand. (Otherwise, I inevitably would forget to reset my testing environment.)

It works perfectly when I run php artisan mydusk.

But how can I edit it to handle optional arguments of a file and filter, the same way I'd be able to call something like php artisan dusk tests/Browser/MailcheckTest.php --filter testBasicValidCaseButtonClick?

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')]);
    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire