exSnake
1 month ago
315
4
Testing

Could a unit test use databases?

Posted 1 month ago by exSnake

Could a unit test use databases?

I mean, i want to make a test that assert if a give role has been assigned

/** @test */
    public function a_admin_is_an_admin()
    {
        $user = factory(\App\User::class)->create();
        $role = factory(\App\Role::class)->create(['name' => 'Admin', 'label' => 'Amministratore']);
        $user->assignRole($role);

        $this->assertEquals(true, $user->isAdmin());
    }

Is this an unit or a feature test?

If it is a Unit test, should it use database?

If not how i can rewrite this?

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