calls[] = 'addInstallmentSequenceColumn'; } protected function ensureIndexes(): void { $this->calls[] = 'ensureIndexes'; } protected function ensureConfigurationDefaults(): void { $this->calls[] = 'ensureConfigurationDefaults'; } protected function archivePaypalTables(): void { $this->calls[] = 'archivePaypalTables'; } protected function refreshFinancialNavItems(): void { $this->calls[] = 'refreshFinancialNavItems'; } protected function restorePaypalTables(): void { $this->calls[] = 'restorePaypalTables'; } protected function dropIndexIfExists(string $table, string $indexName): void { $this->calls[] = "dropIndexIfExists:$table:$indexName"; } } class FinancialSystemLedgerCleanupTest extends CIUnitTestCase { public function testUpRunsCleanupStepsInExpectedOrder(): void { $migration = new TestableFinancialSystemLedgerCleanup(); $migration->up(); $this->assertSame([ 'addInstallmentSequenceColumn', 'ensureIndexes', 'ensureConfigurationDefaults', 'archivePaypalTables', 'refreshFinancialNavItems', ], $migration->calls); } public function testDownRestoresPaypalAndDropsFinancialIndexes(): void { $migration = new TestableFinancialSystemLedgerCleanup(); $fakeDb = new class () { public function tableExists(string $name): bool { return false; } public function fieldExists(string $field, string $table): bool { return false; } }; $fakeForge = new class () { public array $dropped = []; public function dropColumn(string $table, string $column): void { $this->dropped[] = [$table, $column]; } }; self::setPrivateProperty($migration, 'db', $fakeDb); self::setPrivateProperty($migration, 'forge', $fakeForge); $migration->down(); $this->assertSame('restorePaypalTables', $migration->calls[0]); $this->assertContains('dropIndexIfExists:payments:uniq_payments_transaction_id', $migration->calls); $this->assertContains('dropIndexIfExists:invoice_event:idx_invoice_event_invoice_id', $migration->calls); } }