110 lines
5.0 KiB
PHP
110 lines
5.0 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 $bindings): array {
|
|
UpstreamReadOnlyQuery::assertReadOnlySql($sql);
|
|
$this->assertStringContainsString('[dbo].[pm_edgeBandData]', $sql);
|
|
$this->assertStringContainsString('[dbo].[pm_edgeBandApplyDetail]', $sql);
|
|
$this->assertStringContainsString('[dbo].[pm_edgeBandProfitInfo]', $sql);
|
|
$this->assertSame(['%FBT442%', 1, 25], $bindings);
|
|
|
|
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(['raw_code' => 'FBT442'], 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 $bindings): array {
|
|
UpstreamReadOnlyQuery::assertReadOnlySql($sql);
|
|
$this->assertStringContainsString('[dbo].[finance_edgeBandDeductio]', $sql);
|
|
$this->assertStringContainsString('[dbo].[pm_edgeBandApplyDetail]', $sql);
|
|
$this->assertStringContainsString('AS reconciliation_amount', $sql);
|
|
$this->assertStringContainsString('AS price_difference', $sql);
|
|
$this->assertStringContainsString('AS profit', $sql);
|
|
$this->assertStringContainsString('requisition_no, number_type, delivery_no', $sql);
|
|
$this->assertSame(['%JSN10972026070203CK%', '%JSN10972026070203CK%', 1, 25], $bindings);
|
|
|
|
return [[
|
|
'production_code' => 'FBT440',
|
|
'outbound_quantity' => '14000.00',
|
|
'number_type' => '补领',
|
|
'total_count' => 1,
|
|
]];
|
|
}
|
|
);
|
|
|
|
$factory = $this->createMock(UpstreamReadOnlyQueryFactory::class);
|
|
$factory->expects($this->once())->method('forSource')->with('jiansun')->willReturn($query);
|
|
|
|
$result = (new EdgeBandingRepository($factory))->details([
|
|
'outbound_no' => 'JSN10972026070203CK',
|
|
], 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]);
|
|
}
|
|
}
|