78 lines
2.8 KiB
PHP
78 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository;
|
|
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery;
|
|
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class PinduoduoSpreadBillRepositoryTest extends TestCase
|
|
{
|
|
public function test_income_and_expense_filters_are_applied_to_list_and_summary_queries(): void
|
|
{
|
|
$query = new class('jiansun') extends UpstreamReadOnlyQuery {
|
|
/** @var array<int,array{method:string,sql:string,bindings:array}> */
|
|
public array $calls = [];
|
|
|
|
public function scalar(string $sql, array $bindings = []): mixed
|
|
{
|
|
$this->calls[] = compact('sql', 'bindings') + ['method' => 'scalar'];
|
|
|
|
return 1;
|
|
}
|
|
|
|
public function select(string $sql, array $bindings = []): array
|
|
{
|
|
$this->calls[] = compact('sql', 'bindings') + ['method' => 'select'];
|
|
|
|
return [[
|
|
'shopName' => '测试店铺',
|
|
'amount' => 100,
|
|
'balance' => 200,
|
|
'summary' => '测试',
|
|
'flowType' => 1,
|
|
'toAdvertiserFundType' => 1,
|
|
'createTime' => '2026-07-23 12:00:00',
|
|
]];
|
|
}
|
|
|
|
public function first(string $sql, array $bindings = []): ?array
|
|
{
|
|
$this->calls[] = compact('sql', 'bindings') + ['method' => 'first'];
|
|
|
|
return [
|
|
'income_total' => 0,
|
|
'expense_total' => 100,
|
|
'cnt' => 1,
|
|
];
|
|
}
|
|
};
|
|
|
|
$factory = new class($query) extends UpstreamReadOnlyQueryFactory {
|
|
public function __construct(private readonly UpstreamReadOnlyQuery $query)
|
|
{
|
|
}
|
|
|
|
public function forSource(string $source): UpstreamReadOnlyQuery
|
|
{
|
|
TestCase::assertSame('jiansun', $source);
|
|
|
|
return $this->query;
|
|
}
|
|
};
|
|
|
|
$repository = new PinduoduoSpreadBillRepository($factory);
|
|
|
|
$page = $repository->paginate(null, null, null, 'income', 1, 25);
|
|
$summary = $repository->summary(null, null, null, 'expense');
|
|
|
|
$this->assertSame(1, $page['total']);
|
|
$this->assertSame('收入', $page['rows'][0]['income_expense_type']);
|
|
$this->assertSame(-100.0, $summary['net']);
|
|
$this->assertStringContainsString('flowType = 1', $query->calls[0]['sql']);
|
|
$this->assertStringContainsString('flowType = 1', $query->calls[1]['sql']);
|
|
$this->assertStringContainsString('flowType = 2', $query->calls[2]['sql']);
|
|
}
|
|
}
|