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
.
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')]);
}
}
As you can see, I've already read these docs and understand how to write the $signature
to accept optional arguments.
My goal is to be able to sometimes run php artisan mydusk
and also be able to optionally add arguments such as when I might want to call something like php artisan mydusk tests/Browser/MailcheckTest.php --filter testBasicValidCaseButtonClick
(which would pass the tests/Browser/MailcheckTest.php --filter testBasicValidCaseButtonClick
arguments through to the normal dusk
command).
How can I edit the last 2 lines of my handle()
function so that $file
gets passed to dusk
?
I was surprised to learn from my experiments that my original function actually works as I desired, and I can remove the inert line ($file = $this->argument('file');
).
Passing the file
argument through \Artisan::call()
actually does not seem to be necessary at all.
@fubar's answer seems to have made the same mistaken assumptions as I originally did.
As @Jonas Staudenmeir hinted in a comment, Laravel\Dusk\Console\DuskCommand
uses arguments from $_SERVER['argv']
.