CaiWuXiTong/tests/Unit/EcommerceFinance/ProductPriceRepositoryTest.php
WuYongJie 7a3857e10f 修复商品价格读取实时价格日志
商品价格改为读取当前价格调整日志表,并补充查询映射与回归测试。
2026-08-14 10:10:34 +08:00

58 lines
2.9 KiB
PHP

<?php
namespace Tests\Unit\EcommerceFinance;
use Modules\EcommerceFinance\Repositories\ProductPriceRepository;
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery;
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory;
use PHPUnit\Framework\TestCase;
class ProductPriceRepositoryTest extends TestCase
{
public function test_filters_are_parameterized_and_page_queries_overfetch_one_row(): 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_priceAdjustment_log]', $sql);
$this->assertStringContainsString('[skucode] LIKE ?', $sql);
$this->assertStringContainsString("CASE [priceType] WHEN '0' THEN N'定价' WHEN '1' THEN N'变价'", $sql);
$this->assertStringContainsString("WHEN '1' THEN N'清货变价'", $sql);
$this->assertStringContainsString("WHEN '2' THEN N'阶段变价'", $sql);
$this->assertStringContainsString("WHEN '4' THEN N'打折入库'", $sql);
$this->assertStringContainsString("CASE [isCostReduction] WHEN '1' THEN N'是' WHEN '0' THEN N'否'", $sql);
$this->assertStringContainsString('[effectStartTime] < DATEADD(day, 1, CAST(? AS date))', $sql);
$this->assertStringContainsString('OFFSET 2 ROWS FETCH NEXT 3 ROWS ONLY', $sql);
$this->assertSame(
['%ABC\\%\\_%', '0', '1', '2026-07-01', '2026-07-31'],
$bindings,
);
return [
['barcode' => 'A', 'price_before' => '10.00', 'price_after' => '11.50', 'price_diff' => '1.50'],
['barcode' => 'B', 'price_before' => '', 'price_after' => null, 'price_diff' => '0.00'],
['barcode' => 'C', 'price_before' => '3.00', 'price_after' => '4.00', 'price_diff' => '1.00'],
];
},
);
$factory = $this->createMock(UpstreamReadOnlyQueryFactory::class);
$factory->expects($this->once())->method('forSource')->with('jiansun')->willReturn($query);
$result = (new ProductPriceRepository($factory))->paginate([
'barcode' => 'ABC%_',
'price_type' => 'pricing',
'cost_reduction' => 'yes',
'effective_from' => '2026-07-01',
'effective_to' => '2026-07-31',
], 2, 2);
$this->assertCount(3, $result['rows']);
$this->assertSame(10.0, $result['rows'][0]['price_before']);
$this->assertSame(11.5, $result['rows'][0]['price_after']);
$this->assertNull($result['rows'][1]['price_before']);
$this->assertSame(0.0, $result['rows'][1]['price_diff']);
}
}