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"); } // 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 { 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(); // 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 */ private function tableList(): array { return collect(Schema::getTables()) ->pluck('name') ->reject(fn (string $n) => str_starts_with($n, 'sqlite_') || $n === 'migrations') ->values() ->all(); } }