CaiWuXiTong/tests/Feature/Console/BillImportPerformanceResyncTest.php

97 lines
3.5 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\Feature\Console;
use Mockery;
use Modules\EcommerceFinance\Services\BillPerformanceResyncDispatcher;
use Modules\EcommerceFinance\Services\DewuSettlementBillImporter;
use Modules\EcommerceFinance\Services\PinduoduoSettlementBillImporter;
use Modules\EcommerceFinance\Services\TaobaoAlipaySettlementBillImporter;
use Modules\EcommerceFinance\Services\TaobaoWechatSettlementBillImporter;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
class BillImportPerformanceResyncTest extends TestCase
{
/** @return iterable<string,array{class-string,string,array<string,int>}> */
public static function importCommands(): iterable
{
yield 'taobao alipay' => [
TaobaoAlipaySettlementBillImporter::class,
'taobao-alipay',
['business_type_counts' => []],
];
yield 'taobao wechat' => [
TaobaoWechatSettlementBillImporter::class,
'taobao-wechat',
['entry_type_counts' => []],
];
yield 'pinduoduo' => [
PinduoduoSettlementBillImporter::class,
'pinduoduo',
['account_type_counts' => []],
];
yield 'dewu' => [
DewuSettlementBillImporter::class,
'dewu',
['channel_counts' => []],
];
}
#[DataProvider('importCommands')]
public function test_authoritative_import_queues_the_affected_performance_month(
string $importerClass,
string $platform,
array $extraResult,
): void {
$result = array_replace([
'status' => 'succeeded',
'row_count' => 10,
'excluded_rows' => 0,
'excluded_account_rows' => 0,
'store_count' => 2,
'bill_item_count' => 3,
'income_total' => '100.00',
'expense_total' => '20.00',
'net_total' => '80.00',
'period_start' => '2026-10-29',
'period_end' => '2026-11-02',
'source_sha256' => str_repeat('a', 64),
], $extraResult);
$importer = Mockery::mock($importerClass);
$importer->shouldReceive('import')
->once()
->with('bill.xlsx', '2026-10-29', '2026-11-02', 10, '100.00', '20.00', 1000)
->andReturn($result);
$resync = Mockery::mock(BillPerformanceResyncDispatcher::class);
$resync->shouldReceive('dispatch')
->once()
->with($platform, '2026-10-29', '2026-11-02')
->andReturn(['jobs' => 2, 'months' => ['2026-10', '2026-11']]);
$this->app->instance($importerClass, $importer);
$this->app->instance(BillPerformanceResyncDispatcher::class, $resync);
$command = [
TaobaoAlipaySettlementBillImporter::class => 'taobao-alipay-bills:import-authoritative',
TaobaoWechatSettlementBillImporter::class => 'taobao-wechat-bills:import-authoritative',
PinduoduoSettlementBillImporter::class => 'pinduoduo-bills:import-authoritative',
DewuSettlementBillImporter::class => 'dewu-bills:import-authoritative',
][$importerClass];
$this->artisan($command, [
'path' => 'bill.xlsx',
'--from' => '2026-10-29',
'--to' => '2026-11-02',
'--expected-count' => 10,
'--expected-income' => '100.00',
'--expected-expense' => '20.00',
'--batch' => 1000,
])
->expectsOutputToContain('业绩明细重算已排队:2026-10、2026-11(新增 2 个任务)')
->assertSuccessful();
}
}