4
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user