Files
siakad/tests/TestCase.php
T
2026-10-24 11:45:32 +07:00

34 lines
929 B
PHP

<?php
namespace Tests;
use App\Enums\Role;
use App\Models\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
protected function setUp(): void
{
parent::setUp();
// Aset Vite tidak dibutuhkan; tes tidak boleh bergantung pada `npm run build`.
$this->withoutVite();
}
/**
* Buat akun untuk role tertentu beserta baris profilnya.
*
* @param array<string, mixed> $attributes kolom akun (name, username, is_active, ...)
* @param array<string, mixed> $profile kolom profil (nim, nip, ...)
*/
protected function userWithRole(Role $role, array $attributes = [], array $profile = []): User
{
$user = User::factory()->state(['role' => $role])->create($attributes);
$role->profileModel()::factory()->create(['user_id' => $user->id, ...$profile]);
return $user;
}
}