CaiWuXiTong/tests/Unit/EcommerceFinance/LockFinanceLedgerMonthlyOpeningTest.php

117 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Unit\EcommerceFinance;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class LockFinanceLedgerMonthlyOpeningTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
config([
'database.connections.business_mirror' => [
'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,
],
[
'txn_date' => '2026-11-01',
'source' => 'bank_statement',
'source_value' => '6200000000000002',
'income' => 100,
'expense' => 0,
'balance' => 110,
],
]);
}
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');
}
}