[ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], 'upstream_mirrors.connection' => 'business_mirror', ]); DB::purge('business_mirror'); $schema = Schema::connection('business_mirror'); $schema->create('fin_accounts', function (Blueprint $table): void { $table->increments('id'); $table->string('account_short'); $table->string('account_no')->nullable(); }); $schema->create('fin_account_opening', function (Blueprint $table): void { $table->increments('id'); $table->string('account_short'); $table->date('opening_date'); $table->decimal('opening_balance', 18, 2); $table->string('remark')->nullable(); $table->timestamps(); }); $schema->create('fin_transactions', function (Blueprint $table): void { $table->increments('id'); $table->date('txn_date'); $table->string('source'); $table->string('source_value')->nullable(); $table->decimal('income', 18, 2)->default(0); $table->decimal('expense', 18, 2)->default(0); $table->decimal('balance', 18, 2)->nullable(); }); $schema->create('fin_bank_direct_bills', function (Blueprint $table): void { $table->increments('id'); $table->string('account_no'); $table->date('txn_date'); $table->timestamp('txn_at')->nullable(); $table->decimal('income', 18, 2)->default(0); $table->decimal('expense', 18, 2)->default(0); $table->decimal('balance', 18, 2)->nullable(); }); $schema->create('fin_bank_direct_balance_snapshots', function (Blueprint $table): void { $table->increments('id'); $table->string('account_no'); $table->date('balance_date'); $table->timestamp('balance_at')->nullable(); $table->decimal('account_balance', 18, 2)->nullable(); $table->decimal('available_balance', 18, 2); }); $db = DB::connection('business_mirror'); $db->table('fin_accounts')->insert([ ['account_short' => '有银行余额账户', 'account_no' => '6200000000000001'], ['account_short' => '无依据账户', 'account_no' => '6200000000000002'], ]); $db->table('fin_transactions')->insert([ 'txn_date' => '2026-10-31', 'source' => 'bank_statement', 'source_value' => '6200000000000001', 'income' => 0, 'expense' => 85000, 'balance' => 412.44, ]); } protected function tearDown(): void { DB::purge('business_mirror'); parent::tearDown(); } public function test_it_locks_the_previous_month_last_real_balance(): void { $this->artisan('finance-ledger:lock-monthly-opening', [ 'date' => '2026-11-01', '--apply' => true, ])->expectsOutputToContain('新增:1') ->expectsOutputToContain('无真实余额 1') ->assertSuccessful(); $this->assertDatabaseHas('fin_account_opening', [ 'account_short' => '有银行余额账户', 'opening_date' => '2026-11-01', 'opening_balance' => 412.44, ], 'business_mirror'); $this->assertDatabaseMissing('fin_account_opening', [ 'account_short' => '无依据账户', 'opening_date' => '2026-11-01', ], 'business_mirror'); } }