previousDefaultConnection = DB::getDefaultConnection(); config([ 'database.connections.' . self::CONNECTION => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'ak_', 'foreign_key_constraints' => false, ], ]); DB::purge(self::CONNECTION); DB::setDefaultConnection(self::CONNECTION); DB::connection(self::CONNECTION)->getPdo(); } protected function tearDown(): void { DB::disconnect(self::CONNECTION); DB::setDefaultConnection($this->previousDefaultConnection); parent::tearDown(); } public function testFinanceMigrationResumesAfterTheFirstTableWasCreatedBeforeTheLedgerEntry(): void { $this->createCompaniesTable(); $this->createCompatibleTaxDataTable(); $migration = require database_path('migrations/2026_07_21_000000_create_business_finance_tables.php'); $migration->up(); $migration->up(); foreach ([ 'ak_biz_tax_data', 'ak_biz_sw_planning', 'biz_sw_actual', 'biz_company_stores', 'ak_biz_store_changes', 'ak_biz_invoice_basic', 'ak_biz_store_invoice', 'ak_biz_fund_forecast', 'ak_biz_store_receiving_accounts', 'ak_biz_bank_accounts', 'ak_biz_express_receiving', ] as $table) { $this->assertTrue(Schema::hasTable($table), "Expected {$table} to exist after resuming the migration."); } } public function testFinanceMigrationRejectsAnIncompatiblePartialTable(): void { $this->createCompaniesTable(); Schema::create('ak_biz_tax_data', function (Blueprint $table) { $table->id(); }); $migration = require database_path('migrations/2026_07_21_000000_create_business_finance_tables.php'); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('ak_biz_tax_data'); $migration->up(); } public function testBasicInformationMigrationResumesAfterItsFirstTableWasCreated(): void { Schema::create('business_company_information', function (Blueprint $table) { $table->increments('id'); $table->integer('company_id'); $table->string('unified_social_credit_code')->nullable(); $table->string('company_name')->nullable(); $table->text('business_scope')->nullable(); $table->text('shareholders')->nullable(); $table->timestamps(); $table->softDeletes(); }); $migration = require database_path('migrations/2026_07_22_000000_create_business_basic_information_tables.php'); $migration->up(); $migration->up(); $this->assertTrue(Schema::hasTable('business_company_information')); $this->assertTrue(Schema::hasTable('business_store_information')); } private function createCompaniesTable(): void { Schema::create('companies', function (Blueprint $table) { $table->id(); }); } private function createCompatibleTaxDataTable(): void { Schema::create('ak_biz_tax_data', function (Blueprint $table) { $table->id(); $table->unsignedInteger('company_id'); $table->string('company_name')->default(''); $table->decimal('real_ship_revenue', 18, 2)->default(0); $table->decimal('final_tax_revenue', 18, 2)->default(0); $table->string('period')->default(''); $table->timestamps(); }); } }