100 lines
3.8 KiB
PHP
100 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use App\Business\CompanyPlan\CompanyPlanRepository;
|
|
use App\Business\CompanyPlan\CompanyPlanShopRepository;
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Services\PerformanceDetailSubjectMatcher;
|
|
use Modules\EcommerceFinance\Services\StoreReportPeriodBuilder;
|
|
use Tests\TestCase;
|
|
|
|
class PerformanceDetailSubjectMatcherTest extends TestCase
|
|
{
|
|
private string $databasePath;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->databasePath = sys_get_temp_dir() . '/caiwu-performance-subjects-' . bin2hex(random_bytes(6)) . '.sqlite';
|
|
config(['company_plan.database_path' => $this->databasePath]);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
foreach ([$this->databasePath, $this->databasePath . '-wal', $this->databasePath . '-shm'] as $path) {
|
|
if (is_file($path)) {
|
|
unlink($path);
|
|
}
|
|
}
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_it_uses_the_current_subject_and_company_plan_taxpayer_type(): void
|
|
{
|
|
$periods = Mockery::mock(StoreReportPeriodBuilder::class);
|
|
$periods->shouldReceive('currentCompanies')->once()->andReturn([
|
|
'店铺A' => '主体乙有限公司',
|
|
]);
|
|
$plans = app(CompanyPlanRepository::class);
|
|
$shops = app(CompanyPlanShopRepository::class);
|
|
$plans->importRows(1, [
|
|
[
|
|
'company_name' => '主体甲有限公司',
|
|
'taxpayer_type' => '一般纳税人',
|
|
'registered_at' => '2025-01-01',
|
|
],
|
|
[
|
|
'company_name' => '主体乙有限公司',
|
|
'taxpayer_type' => '小规模纳税人',
|
|
'registered_at' => '2026-09-20',
|
|
],
|
|
[
|
|
'company_name' => '历史主体有限公司',
|
|
'taxpayer_type' => '小规模纳税人',
|
|
'registered_at' => '2025-01-01',
|
|
],
|
|
[
|
|
'company_name' => '接替主体有限公司',
|
|
'taxpayer_type' => '一般纳税人',
|
|
'registered_at' => '2026-09-01',
|
|
],
|
|
], 'update', null);
|
|
$shops->pdo()->exec(
|
|
"INSERT INTO company_plan_shops "
|
|
. "(company_id, company_name, shop_name, shop_status, successor, created_at, updated_at) VALUES "
|
|
. "(1, '历史主体有限公司', '店铺C', '正常', '接替主体有限公司', '2026-01-01', '2026-01-01')"
|
|
);
|
|
|
|
$matcher = new PerformanceDetailSubjectMatcher($periods, $plans, $shops);
|
|
$map = $matcher->map(['店铺A', '店铺C'], 1);
|
|
|
|
$historical = $matcher->apply((object) [
|
|
'store_name' => '店铺A',
|
|
'occurred_date' => '2026-09-15',
|
|
], $map);
|
|
$current = $matcher->apply((object) [
|
|
'store_name' => '店铺A',
|
|
'occurred_date' => '2026-10-15',
|
|
], $map);
|
|
$fallback = $matcher->apply((object) [
|
|
'store_name' => '店铺C',
|
|
'occurred_date' => '2026-11-05',
|
|
], $map);
|
|
|
|
// 业绩发生在旧主体期间,也统一显示店铺当前存续的新主体。
|
|
$this->assertSame('主体乙有限公司', $historical->company_name);
|
|
$this->assertSame('小规模纳税人', $historical->taxpayer_type);
|
|
$this->assertSame('主体乙有限公司', $current->company_name);
|
|
$this->assertSame('小规模纳税人', $current->taxpayer_type);
|
|
|
|
$this->assertSame('接替主体有限公司', $fallback->company_name);
|
|
$this->assertSame('一般纳税人', $fallback->taxpayer_type);
|
|
$this->assertFalse(property_exists($historical, 'subject_effective_at'));
|
|
$this->assertFalse(property_exists($historical, 'company_status'));
|
|
}
|
|
}
|