S2a: purge legacy Form Builder PHP code and routes

This commit is contained in:
2026-04-17 18:43:00 +02:00
parent cfc7610497
commit a3ca596362
55 changed files with 128 additions and 6057 deletions

View File

@@ -6,28 +6,25 @@ namespace Tests\Feature;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* Hard-resets the test database via migrate:fresh, rolls back every
* form-builder migration in reverse, asserts the new tables are gone (and
* legacy tables remain Phase 8 was deferred to S2 per S1 wrap-up), then
* re-applies and asserts the table list matches the post-fresh snapshot.
* Sanity-checks the Form Builder migration chain after S2a.
*
* Slow because we exercise the real migrator against the real database.
* Tagged "slow" so CI can parallel-isolate or skip it where needed.
* Post-S2a: the legacy registration_* tables are DROPPED by a one-way
* migration (2026_04_20_100000_drop_remaining_legacy_registration_tables).
* Rolling back that migration throws by design restoring the legacy
* tables from the new form_* structure would be lossy.
*
* Tagged "slow" because it exercises the real migrator.
*/
#[Group('slow')]
final class MigrationRollbackTest extends TestCase
{
use WithoutMiddleware;
/** Migration steps added in S1 (Phase 3 + Phase 4). */
private const S1_MIGRATION_STEPS = 14;
private const FORM_BUILDER_TABLES = [
'user_profiles',
'form_schemas',
@@ -44,71 +41,37 @@ final class MigrationRollbackTest extends TestCase
'form_webhook_deliveries',
];
public function test_form_builder_migrations_are_fully_reversible(): void
private const LEGACY_TABLES = [
'registration_form_fields',
'person_field_values',
'registration_field_templates',
];
public function test_form_builder_tables_present_after_migrate_fresh(): void
{
Artisan::call('migrate:fresh');
$beforeTables = $this->tableList();
// S1 leaves the legacy registration_* tables in place — Phase 8
// was deferred to S2. Sanity-check that assumption is still true.
foreach (['registration_form_fields', 'person_field_values', 'registration_field_templates'] as $legacy) {
$this->assertTrue(Schema::hasTable($legacy), "legacy table {$legacy} should still exist after S1");
}
// Every form-builder table is present after fresh.
foreach (self::FORM_BUILDER_TABLES as $table) {
$this->assertTrue(Schema::hasTable($table), "{$table} should exist after migrate:fresh");
}
// Roll back exactly the S1 migration steps.
Artisan::call('migrate:rollback', ['--step' => self::S1_MIGRATION_STEPS]);
// All form-builder tables should now be gone.
foreach (self::FORM_BUILDER_TABLES as $table) {
$this->assertFalse(Schema::hasTable($table), "{$table} should be dropped by rollback");
foreach (self::LEGACY_TABLES as $legacy) {
$this->assertFalse(
Schema::hasTable($legacy),
"legacy table {$legacy} should NOT exist after S2a purge"
);
}
// Legacy tables remain untouched by the rollback.
$this->assertTrue(Schema::hasTable('registration_form_fields'));
// Re-apply: tables are recreated, table list matches snapshot.
Artisan::call('migrate');
$afterTables = $this->tableList();
sort($beforeTables);
sort($afterTables);
$this->assertSame($beforeTables, $afterTables);
}
public function test_user_profiles_populate_migration_down_clears_backfilled_rows(): void
public function test_drop_legacy_tables_migration_is_one_way(): void
{
Artisan::call('migrate:fresh');
// The populate migration ran during fresh. Assert it left rows for
// any users present at migrate time (test DB has none, so 0 is OK).
$populatedCount = DB::table('user_profiles')->count();
// step=1 targets the most recent migration — the S2a drop —
// whose down() is a hard failure.
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Legacy registration tables cannot be restored');
// down() of the populate migration deletes all profiles.
Artisan::call('migrate:rollback', ['--step' => self::S1_MIGRATION_STEPS - 1]);
Artisan::call('migrate:rollback', ['--step' => 1]); // populate step
// Next rollback step now drops the table — handled by the other test.
// Re-apply for clean state for subsequent tests.
Artisan::call('migrate');
// Sanity: counts can be compared before/after but tests are isolated
// per RefreshDatabase so we mainly assert no exceptions.
$this->assertSame($populatedCount, DB::table('user_profiles')->count());
}
/**
* @return array<int, string>
*/
private function tableList(): array
{
return collect(Schema::getTables())
->pluck('name')
->reject(fn (string $n) => str_starts_with($n, 'sqlite_') || $n === 'migrations')
->values()
->all();
Artisan::call('migrate:rollback', ['--step' => 1]);
}
}