49 lines
1.9 KiB
PHP
49 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use App\Console\Commands\SyncStoreReceiptOrderMatches;
|
|
use Modules\EcommerceFinance\Services\AccountLedgerRemarkMap;
|
|
use ReflectionClass;
|
|
use ReflectionMethod;
|
|
use Tests\TestCase;
|
|
|
|
class StoreReceiptMappingPreviewOverrideTest extends TestCase
|
|
{
|
|
public function test_default_compensation_is_separate_from_offset_remarks(): void
|
|
{
|
|
$reflection = new ReflectionClass(SyncStoreReceiptOrderMatches::class);
|
|
$offsetRemarks = $reflection->getConstant('OFFSET_REMARKS');
|
|
$defaultCompensationRemarks = $reflection->getConstant('DEFAULT_COMPENSATION_REMARKS');
|
|
|
|
$this->assertSame(['冲减收入'], $offsetRemarks);
|
|
$this->assertSame(['违约赔付(冲减收入)'], $defaultCompensationRemarks);
|
|
}
|
|
|
|
public function test_local_mapping_override_file_is_used_when_configured(): void
|
|
{
|
|
$path = tempnam(sys_get_temp_dir(), 'caiwu-mapping-override-');
|
|
$this->assertNotFalse($path);
|
|
file_put_contents($path, json_encode([
|
|
['platform' => '京东', 'item' => '结算单', 'memo' => '订单收入'],
|
|
['platform' => '京东', 'item' => '售后卖家赔付费', 'memo' => '违约赔付(冲减收入)'],
|
|
], JSON_UNESCAPED_UNICODE));
|
|
|
|
$previous = getenv('ACCOUNT_MAPPING_OVERRIDE_FILE');
|
|
putenv('ACCOUNT_MAPPING_OVERRIDE_FILE=' . $path);
|
|
|
|
try {
|
|
$method = new ReflectionMethod(AccountLedgerRemarkMap::class, 'accountMappingOverrideRules');
|
|
$rules = $method->invoke(new AccountLedgerRemarkMap());
|
|
|
|
$this->assertCount(2, $rules);
|
|
$this->assertSame('违约赔付(冲减收入)', $rules[1]['memo']);
|
|
} finally {
|
|
putenv($previous === false
|
|
? 'ACCOUNT_MAPPING_OVERRIDE_FILE'
|
|
: 'ACCOUNT_MAPPING_OVERRIDE_FILE=' . $previous);
|
|
@unlink($path);
|
|
}
|
|
}
|
|
}
|