-1

(Updated question to show that it's not like the linked questions)

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?

Ryan
  • 22,332
  • 31
  • 176
  • 357
  • 4
    Have you read the manual? It gives examples. https://laravel.com/docs/5.6/artisan#defining-input-expectations – fubar Jul 02 '18 at 01:55
  • Possible duplicate of [How to pass multiple arguments when running Laravel Tasks on command line?](https://stackoverflow.com/questions/14394597/how-to-pass-multiple-arguments-when-running-laravel-tasks-on-command-line) – Sagar Ahuja Jul 02 '18 at 06:22
  • @fubar Yes, I'd already read those docs. I feel like maybe you didn't read my question. In any case, I've edited it now to try to make it clearer. Thanks for your help. :-) – Ryan Jul 02 '18 at 16:17

3 Answers3

0

You can have a look at these links too it might help you.

Stack Answer 1

Stack Answer 2

Sagar Ahuja
  • 726
  • 6
  • 23
  • Thanks but I'd already read those links. I feel like maybe you didn't read my question. In any case, I've edited it now to try to make it clearer. Thanks for your help. :-) – Ryan Jul 02 '18 at 16:18
  • 1
    No problem i will post if i can help @Ryan – Sagar Ahuja Jul 03 '18 at 05:59
0

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'].

Ryan
  • 22,332
  • 31
  • 176
  • 357
0

Use signature without '--' to provide arguments

return \Artisan::call('dusk', ['file' => $file , '--filter' => $this->option('filter')]);

The documentation does give an example but it is not stated clearly (it assumes you followed all the statements in the sections above)

For the signature below

protected $signature = 'email:send {user} {--queue}';

It gives (on very far below) this example as calling an Artisan command from other commands

public function handle()
{
    $this->call('email:send', [
        'user' => 1, '--queue' => 'default'
    ]);
}

https://laravel.com/docs/5.6/artisan#calling-commands-from-other-commands