CaiWuXiTong/tests/Unit/Business/StoreReceiptPlatformSkuMapperTest.php
chenxi e15b6b9901 商品成本:按历史唯一规格映射平台数字SKU (#482)
平台数字 SKU 仅按唯一历史内部编码自动映射;多候选保持待核验。
2026-10-24 10:18:21 +08:00

87 lines
2.9 KiB
PHP

<?php
namespace Tests\Unit\Business;
use App\Business\StoreReceiptPlatformSkuMapper;
use PHPUnit\Framework\TestCase;
class StoreReceiptPlatformSkuMapperTest extends TestCase
{
public function test_unique_historical_internal_sku_is_mapped(): void
{
$mapper = new StoreReceiptPlatformSkuMapper([
$this->row('958530694526', '3768947181063635112', '3768947181063635112'),
$this->row('SG006367N1028V01', 'SG0063', '3768947181063635112'),
$this->row('SG006367N1028V01', 'SG0063', '3768947181063635112'),
]);
$result = $mapper->resolve('3533103677164802', '3768947181063635112');
$this->assertSame('unique', $result['status']);
$this->assertSame('SG006367N1028V01', $result['internal_sku']);
$this->assertSame(2, $result['history_rows']);
$this->assertSame(['经典北美黑胡桃色'], $result['internal_properties']);
}
public function test_multiple_internal_skus_remain_ambiguous(): void
{
$mapper = new StoreReceiptPlatformSkuMapper([
$this->row('SG001', 'SGSTYLE1', '3768947181063635112'),
$this->row('SG002', 'SGSTYLE2', '3768947181063635112'),
]);
$result = $mapper->resolve('3533103677164802', '3768947181063635112');
$this->assertSame('ambiguous', $result['status']);
$this->assertNull($result['internal_sku']);
$this->assertSame(['SG001', 'SG002'], $result['candidates']);
}
public function test_missing_history_stays_unmapped(): void
{
$mapper = new StoreReceiptPlatformSkuMapper([
$this->row('958530694526', '3768947181063635112', '3768947181063635112'),
]);
$result = $mapper->resolve('3533103677164802', '3768947181063635112');
$this->assertSame('missing', $result['status']);
$this->assertNull($result['internal_sku']);
$this->assertSame([], $result['candidates']);
}
public function test_mapping_requires_the_same_platform_spec_id(): void
{
$mapper = new StoreReceiptPlatformSkuMapper([
$this->row(
'SG006367N1028V01',
'SG0063',
'3768947181063635112',
'3533103677164802',
),
]);
$result = $mapper->resolve('3533103677164999', '3768947181063635112');
$this->assertSame('missing', $result['status']);
$this->assertNull($result['internal_sku']);
}
/** @return array<string,string> */
private function row(
string $skuId,
string $itemId,
string $shopItemId,
string $shopSkuId = '3533103677164802',
): array
{
return [
'shop_sku_id' => $shopSkuId,
'shop_i_id' => $shopItemId,
'sku_id' => $skuId,
'i_id' => $itemId,
'properties_value' => $itemId === 'SG0063' ? '经典北美黑胡桃色' : '',
];
}
}