sanne_v_leeuwen's avatar

Undefined array key "argv"

Hi i try to make a command to test my site and display this in a blade: my Livewire/Test.php

<?php
namespace Leeuwenkasteel\Install\Http\Livewire;

use Livewire\Component;
use Artisan;
class Test extends Component{
    public $output = '';

    public function runUnitTest(){
        $result = Artisan::call('test');
        $this->output = Artisan::output();
    }

    public function render()
    {
        return view('installer::livewire.test');
    }
}

My Testscript

<?php

namespace Modules\Auth\Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class AuthTest extends TestCase{
    public function testExample(){
        $this->assertTrue(true);
    }
}

My Blade:

<div>
    <button wire:click="runUnitTest" class="btn btn-primary">Run Unit Test</button>
    <pre>{{ $output }}</pre>
</div>

I got the error: Undefined array key "argv"

0 likes
1 reply
josecameselle's avatar

Use the Artisan::queue method instead of the Artisan::call method to run the test command. This will run the command in the background using a queue worker, which should have access to the $argv variable.

public function runUnitTest()
{
    Artisan::queue('test');
    $this->output = 'Tests have been queued for execution.';
}

Please or to participate in this conversation.