mirror of
https://gitlab.com/DanLegoff/mgap.git
synced 2026-11-16 14:22:37 +00:00
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Spatie\Permission\Models\Role;
|
|
use Spatie\Permission\PermissionRegistrar;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Tests sin RefreshDatabase (sqlite :memory: sin migrar) no tienen las tablas.
|
|
if (! Schema::hasTable(config('permission.table_names.roles', 'auth_roles'))) {
|
|
return;
|
|
}
|
|
|
|
app(PermissionRegistrar::class)->forgetCachedPermissions();
|
|
|
|
foreach (['administrador', 'visor', 'consultor', 'pendiente'] as $rol) {
|
|
Role::firstOrCreate(['name' => $rol, 'guard_name' => 'web']);
|
|
}
|
|
}
|
|
|
|
protected function adminUser(array $attributes = []): User
|
|
{
|
|
return $this->userWithRole('administrador', $attributes);
|
|
}
|
|
|
|
protected function userWithRole(string $rol, array $attributes = []): User
|
|
{
|
|
$user = User::factory()->create($attributes);
|
|
$user->assignRole($rol);
|
|
|
|
return $user;
|
|
}
|
|
}
|