Files
OnAPB-Carrere_Demartin/tests/Feature/SoftDeleteTest.php
T
Laucha1312 aa9bc585fd 4
2026-06-04 15:22:45 -03:00

53 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use App\Models\Club;
use App\Models\Jugador;
use App\Models\Evento;
class SoftDeleteTest extends TestCase
{
use DatabaseTransactions;
public function test_deletion_uses_soft_deletes_on_critical_models()
{
// 1. Setup: Crear un club, jugador y evento
$club = Club::create(['id_club' => 888, 'nombre' => 'Club Borrable']);
$jugador = Jugador::create([
'id_jugador' => 'T-SD-1',
'documento' => '11111111',
'nombre' => 'Borra',
'apellido' => 'Mela',
'id_club_actual' => $club->id_club,
'id_club_origen' => $club->id_club,
'activo' => true
]);
$evento = Evento::create([
'id_evento' => 'UUID-SD-1',
'nombre_evento' => 'Evento Prueba SD',
'fecha_evento' => now()->format('Y-m-d'),
'hora_inicio' => '18:00',
'hora_fin' => '20:00'
]);
// 2. Ejecutar borrado
$club->delete();
$jugador->delete();
$evento->delete();
// 3. Verificar que siguen en la base de datos (físicamente) pero con deleted_at
$this->assertSoftDeleted('clubes', ['id_club' => 888]);
$this->assertSoftDeleted('jugadores', ['id_jugador' => 'T-SD-1']);
$this->assertSoftDeleted('eventos', ['id_evento' => 'UUID-SD-1']);
// 4. Verificar que no aparecen en consultas normales
$this->assertNull(Club::find(888));
// 5. Verificar que aparecen si usamos withTrashed()
$this->assertNotNull(Club::withTrashed()->find(888));
}
}