新增全局流水号
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use AKSRT\Finance\BusinessNumber;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class BusinessNumberTest extends TestCase {
|
||||
public function test_prefix_is_uppercased_filtered_and_limited(): void {
|
||||
self::assertSame('AK', BusinessNumber::normalize_prefix('', 'AK'));
|
||||
self::assertSame('TX_TEST-9', BusinessNumber::normalize_prefix(' tx_测test-9 ', 'TX'));
|
||||
self::assertSame('ABCDEFGHIJKL', BusinessNumber::normalize_prefix('abcdefghijklmnop', 'AK'));
|
||||
self::assertSame('TX', BusinessNumber::normalize_prefix('中文', 'TX'));
|
||||
}
|
||||
|
||||
public function test_candidate_uses_supplied_site_time_and_six_digit_random_suffix(): void {
|
||||
$time = new DateTimeImmutable('2026-08-25 13:14:15', new DateTimeZone('Asia/Shanghai'));
|
||||
self::assertSame('AK20260825131415000007', BusinessNumber::candidate('ak', $time, 7));
|
||||
self::assertMatchesRegularExpression('/^TX\d{14}\d{6}$/', BusinessNumber::candidate('TX', $time, 999999));
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,13 @@ final class LedgerResultTest extends TestCase {
|
||||
public function test_balance_reads_integer_minor_units(): void {
|
||||
$result = new LedgerResult(17, true, [], [
|
||||
4 => ['points' => 25, 'balance' => 1234],
|
||||
]);
|
||||
], 'AK20260825123456000001');
|
||||
self::assertSame(25, $result->balance(4, AssetType::POINTS));
|
||||
self::assertSame(1234, $result->balance(4, AssetType::BALANCE));
|
||||
self::assertSame(0, $result->balance(99, AssetType::BALANCE));
|
||||
self::assertSame(17, $result->to_array()['transaction_id']);
|
||||
self::assertTrue($result->to_array()['replayed']);
|
||||
self::assertSame('AK20260825123456000001', $result->flow_number);
|
||||
self::assertSame('AK20260825123456000001', $result->to_array()['flow_number']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,16 @@ if (!function_exists('sanitize_key')) {
|
||||
return strtolower((string) preg_replace('/[^a-z0-9_\-]/', '', $key));
|
||||
}
|
||||
}
|
||||
if (!function_exists('sanitize_text_field')) {
|
||||
function sanitize_text_field($value): string {
|
||||
return trim(strip_tags((string) $value));
|
||||
}
|
||||
}
|
||||
if (!function_exists('wp_timezone')) {
|
||||
function wp_timezone(): DateTimeZone {
|
||||
return new DateTimeZone('UTC');
|
||||
}
|
||||
}
|
||||
if (!function_exists('wp_json_encode')) {
|
||||
function wp_json_encode($value, int $flags = 0) {
|
||||
return json_encode($value, $flags);
|
||||
@@ -59,3 +69,4 @@ require_once dirname(__DIR__, 2) . '/src/Ledger/AssetAmount.php';
|
||||
require_once dirname(__DIR__, 2) . '/src/Ledger/LedgerCommand.php';
|
||||
require_once dirname(__DIR__, 2) . '/src/Ledger/LedgerResult.php';
|
||||
require_once dirname(__DIR__, 2) . '/src/Ledger/OperationKey.php';
|
||||
require_once dirname(__DIR__, 2) . '/src/Finance/BusinessNumber.php';
|
||||
|
||||
Reference in New Issue
Block a user