CaiWuXiTong/tests/Unit/EcommerceFinance/EdgeBandingRepositoryTest.php

98 lines
4.1 KiB
PHP

<?php
namespace Tests\Unit\EcommerceFinance;
use Modules\EcommerceFinance\Repositories\EdgeBandingRepository;
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery;
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory;
use PHPUnit\Framework\TestCase;
class EdgeBandingRepositoryTest extends TestCase
{
public function test_price_rows_are_normalized_and_paginated(): void
{
$query = $this->createMock(UpstreamReadOnlyQuery::class);
$query->expects($this->once())->method('select')->willReturnCallback(
function (string $sql): array {
UpstreamReadOnlyQuery::assertReadOnlySql($sql);
$this->assertStringContainsString('[dbo].[pm_averageUnitPrice]', $sql);
return [[
'raw_code' => 'FBT442',
'latest_price' => '0.10',
'total_count' => 1,
]];
}
);
$factory = $this->createMock(UpstreamReadOnlyQueryFactory::class);
$factory->expects($this->once())->method('forSource')->with('jiansun')->willReturn($query);
$result = (new EdgeBandingRepository($factory))->prices([], 1, 25);
$this->assertSame(1, $result['total']);
$this->assertSame('FBT442', $result['data'][0]['raw_code']);
$this->assertSame('采购价', $result['data'][0]['price_type']);
$this->assertSame('封边条厂', $result['data'][0]['factory_type']);
$this->assertArrayNotHasKey('total_count', $result['data'][0]);
}
public function test_detail_query_uses_the_read_only_guard(): void
{
$query = $this->createMock(UpstreamReadOnlyQuery::class);
$query->expects($this->once())->method('select')->willReturnCallback(
function (string $sql): array {
UpstreamReadOnlyQuery::assertReadOnlySql($sql);
$this->assertStringContainsString('[dbo].[fys_supplierGoods_sttlement_sale]', $sql);
return [[
'production_code' => 'FBT440',
'outbound_quantity' => '14000.00',
'total_count' => 1,
]];
}
);
$factory = $this->createMock(UpstreamReadOnlyQueryFactory::class);
$factory->expects($this->once())->method('forSource')->with('jiansun')->willReturn($query);
$result = (new EdgeBandingRepository($factory))->details([], 1, 25);
$this->assertSame(1, $result['total']);
$this->assertSame('FBT440', $result['data'][0]['production_code']);
$this->assertSame('米', $result['data'][0]['unit']);
$this->assertSame('正常出库', $result['data'][0]['return_flag']);
$this->assertSame('申领', $result['data'][0]['number_type']);
}
public function test_payable_rows_expose_full_result_totals(): void
{
$query = $this->createMock(UpstreamReadOnlyQuery::class);
$query->expects($this->once())->method('select')->willReturnCallback(
function (string $sql): array {
UpstreamReadOnlyQuery::assertReadOnlySql($sql);
$this->assertStringContainsString('[dbo].[fys_supplierPaymentSummary]', $sql);
return [[
'supplier' => '封边条厂',
'payable_amount' => '100.00',
'summary_payable_amount' => '100.00',
'summary_corporate_payment' => '100.00',
'summary_private_payment' => '0.00',
'total_count' => 1,
]];
}
);
$factory = $this->createMock(UpstreamReadOnlyQueryFactory::class);
$factory->expects($this->once())->method('forSource')->with('jiansun')->willReturn($query);
$result = (new EdgeBandingRepository($factory))->payables(['period' => '2026-06'], 1, 25);
$this->assertSame(1, $result['total']);
$this->assertSame(100.0, $result['totals']['payable_amount']);
$this->assertSame(100.0, $result['totals']['corporate_payment']);
$this->assertArrayNotHasKey('summary_payable_amount', $result['data'][0]);
}
}