Home > Blockchain >  test artisan command laravel 9
test artisan command laravel 9

Time:06-01

I'm trying to write a test command in Laravel 9. In the below code the new user will create successfully But after creating need to redirect the Dashboard page

public function test_an_action_that_requires_authentication()
{
    $user = $this->artisan('make:user',[
        'name' => "username",
        'email' => "useremail",
        'password' => Str::random(8)
    ]);
}

How to redirect to the route after success created

CodePudding user response:

We will use the assertExitCode method to assert that the command completed with a given exit code.

$this->artisan('module:import')
    ->expectsConfirmation('Do you really wish to run this command?', 'no')
    ->assertExitCode(1);

for more information you can find here

https://laravel.com/docs/9.x/console-tests

CodePudding user response:

N.B. This code does not work in test. You can not redirect in an artisan command.

Said that, in laravel, to redirect to the home page, you can use this code in a controller function:

return redirect(url('/'));
  • Related