mercredi 3 février 2021

Is it possible to implement actingAs() function in Laravel if I created another User model?

I'm trying to implement some Laravel tests. I would like to test some authenticated routes, but I'm not using the default user model. I created a new one. Is there a way for me to use the ->actingAs() function?

class HomeTest extends TestCase
{
    /**
     * @test
     */
    public function first_test()
    {

        $user = factory(Usuario::class)->make();
        
        $response = $this
                         ->withoutExceptionHandling()
                         ->actingAs($user)
                         ->get('/ead');
        
        $response->assertStatus(200);
    }
}

The parameter that is received is the Illuminate\Contracts\Auth\Authenticatable

/**
     * Set the currently logged in user for the application.
     *
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * @param  string|null  $driver
     * @return $this
     */
    public function actingAs(UserContract $user, $driver = null)
    {
        return $this->be($user, $driver);
    }

Aucun commentaire:

Enregistrer un commentaire