number6's avatar

Laravel Dusk loginAs not working / using sqlite DB

I am using Laravel Spark 7.0 and trying to use Laravel Dusk to test my application. This is my simple test.

I am trying to create a user and a team, make the user the owner of that team and then start navigating the app. It fails when trying to visit DashboardPage.

The URL does not validate "/home" b/c it's actually still "/login". The screenshot taken is of the login screen. You will also notice I have the dd(User::find($user->id)). It does in fact return a user from the DB.

From my debugging, it appears that the model queries are using sqlite DB, but the browse() requests are pulling from the real dev site (not the Laravel Dusk generated one).

What am I missing?

public function testExample() {
    $user = createWithTeam(User::class);
    $this->browse(function (Browser $browser) use ($user) {
        //dd(User::find($user->id));
        $browser->loginAs($user)
            ->visit(new DashboardPage)
            ->assertSee('Plan Types');

    });
}

        function createWithTeam($class, $attributes = [], $times = null)
    {
        $user = factory(App\User::class)->create();
        $team = factory(App\Team::class)->create();
    
    
        // Use spark interactions from the base controller
        Spark::interact(CreateTeam::class.'@validator', [$user, $team])->validate();
        $team = Spark::interact(CreateTeam::class, [$user, $team]);
        return $user;
    }

I am running the environment with php artisan server --env=dusk.local. This is my dusk.local

APP_ENV="local"
APP_DEBUG=true
APP_LOG_LEVEL="debug"
APP_URL="http://localhost:8000"

DB_CONNECTION="sqlite"

CACHE_DRIVER="file"
SESSION_DRIVER="file"
QUEUE_DRIVER="sync"

edit moved to the testing category.

0 likes
2 replies
shez1983's avatar

i think when you RUN dusk watch your root folder where .env is and you will see dusk creating a new .env.dusk (or something) for the duration of test - i think you just need to make one yourself and laravel will use that - check docs for dusk

number6's avatar

I am unsure as to why it started working, but I run php artisan serve --env=dusk.local and the APP_URL is exactly the same as my normal .env file...and it works.

Please or to participate in this conversation.