56 lines
2.3 KiB
PHP
56 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use InvalidArgumentException;
|
|
use Mockery;
|
|
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
|
use Modules\EcommerceFinance\Repositories\PlatformPromotionAccountRepository;
|
|
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery;
|
|
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class PlatformPromotionAccountRepositoryTest extends TestCase
|
|
{
|
|
use MockeryPHPUnitIntegration;
|
|
|
|
public function test_dashboard_only_queries_the_requested_platform(): void
|
|
{
|
|
$factory = Mockery::mock(UpstreamReadOnlyQueryFactory::class);
|
|
$query = Mockery::mock(UpstreamReadOnlyQuery::class);
|
|
$factory->shouldReceive('forSource')->once()->with('js_data_middle_platform')->andReturn($query);
|
|
$query->shouldReceive('select')->once()->ordered()->with(
|
|
Mockery::on(static fn (string $sql): bool => str_contains($sql, 'SELECT TOP 5000')
|
|
&& str_contains($sql, 'jd_jzt_finance_records')),
|
|
['2026-08'],
|
|
)->andReturn([['shop_name' => '测试店铺', 'amount' => 100]]);
|
|
$query->shouldReceive('select')->once()->ordered()->with(
|
|
Mockery::on(static fn (string $sql): bool => str_contains($sql, 'SUM(CASE WHEN in_out_type')
|
|
&& str_contains($sql, 'jd_jzt_finance_records')),
|
|
['2026-08'],
|
|
)->andReturn([['income' => 100, 'expense' => 0, 'record_count' => 1]]);
|
|
|
|
$result = (new PlatformPromotionAccountRepository($factory))->dashboard([
|
|
'month' => '2026-08',
|
|
'shop_name' => '',
|
|
'account' => '',
|
|
], 5000, 'jd');
|
|
|
|
$this->assertCount(1, $result['jd']);
|
|
$this->assertSame(1, $result['jdSummary']['record_count']);
|
|
$this->assertSame([], $result['dy']);
|
|
$this->assertSame([], $result['dw']);
|
|
$this->assertSame([], $result['vipSales']);
|
|
}
|
|
|
|
public function test_dashboard_rejects_an_unknown_platform_before_connecting(): void
|
|
{
|
|
$factory = Mockery::mock(UpstreamReadOnlyQueryFactory::class);
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
(new PlatformPromotionAccountRepository($factory))->dashboard([
|
|
'month' => '2026-08',
|
|
], 200, 'unknown');
|
|
}
|
|
}
|