ivanmiranda
4 months ago

Artisan::call('dusk') not working. Undefined index: argv thrown

Posted 4 months ago by ivanmiranda

Hello everyone,

I am developing a Laravel app and I trying to introduce some automations using Laravel Dusk. The thing is that I've followed all the instructions pointed on Laravel Docs and this is still failing. I've registered DuskServiceProvider on AppServiceProvider class (by the way, I couldn't find this on the official docs) and I even put the DuskCommand class on kernel's commands protected property, but with no luck.

I'm calling Artisan::call('dusk') from one of my controllers but the tests are not executed. I've retrieved the Artisan::call method response and it prints out 1. The error that I'm facing is 'Undefined index: argv' on the DuskCommand class.

I've also read that this is achievable with Symfony, but I wonder why Artisan::call is not working here. According to official docs:

Sometimes you may wish to execute an Artisan command outside of the CLI. For example, you may wish to fire an Artisan command from a route or controller. You may use the call method on the Artisan facade to accomplish this. The call method accepts either the command's name or class as the first argument, and an array of command parameters as the second argument

My Kernel class:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Laravel\Dusk\Console\DuskCommand;
use Laravel\Dusk\Console\DuskFailsCommand;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        DuskCommand::class, DuskFailscommand::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

The DuskServiceProvider class

<?php

namespace Laravel\Dusk;

use Exception;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class DuskServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any package services.
     *
     * @return void
     */
    public function boot()
    {
        Route::get('/_dusk/login/{userId}/{guard?}', [
            'middleware' => 'web',
            'uses' => 'Laravel\Dusk\Http\Controllers\[email protected]',
        ]);

        Route::get('/_dusk/logout/{guard?}', [
            'middleware' => 'web',
            'uses' => 'Laravel\Dusk\Http\Controllers\[email protected]',
        ]);

        Route::get('/_dusk/user/{guard?}', [
            'middleware' => 'web',
            'uses' => 'Laravel\Dusk\Http\Controllers\[email protected]',
        ]);
    }

    /**
     * Register any package services.
     *
     * @return void
     * @throws Exception
     */
    public function register()
    {
        if ($this->app->environment('production')) {
            throw new Exception('It is unsafe to run Dusk in production.');
        }

            $this->commands([
                Console\InstallCommand::class,
                Console\DuskCommand::class,
                Console\DuskFailsCommand::class,
                Console\MakeCommand::class,
                Console\PageCommand::class,
                Console\ComponentCommand::class,
            ]);
        
    }
}

And the AppServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; 
use Laravel\Dusk\DuskServiceProvider;
use Laravel\Dusk\Console\DuskCommand;
use Laravel\Dusk\Console\MakeCommand;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->register(DuskServiceProvider::class);
        $this->commands(DuskCommand::class);
        $this->commands(MakeCommand::class);
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
}

Thanks!!

Please sign in or create an account to participate in this conversation.