100 lines
3.7 KiB
PHP
100 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use App\Business\CompanyPlan\CompanyPlanRepository;
|
|
use App\Business\CompanyPlan\CompanyPlanShopRepository;
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Services\ProductCostSubjectMatcher;
|
|
use Modules\EcommerceFinance\Services\StoreReportPeriodBuilder;
|
|
use Tests\TestCase;
|
|
|
|
class ProductCostSubjectMatcherTest extends TestCase
|
|
{
|
|
private string $databasePath;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->databasePath = sys_get_temp_dir() . '/caiwu-product-cost-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_store_subject_period_on_the_cost_occurrence_date(): void
|
|
{
|
|
$periods = Mockery::mock(StoreReportPeriodBuilder::class);
|
|
$periods->shouldReceive('build')->once()->andReturn([
|
|
'店铺A' => [
|
|
[
|
|
'company_name' => '主体旧有限公司',
|
|
'effective_at' => '2026-07-01',
|
|
'expires_at' => '2026-09-30',
|
|
'source' => 'initial',
|
|
],
|
|
[
|
|
'company_name' => '主体新有限公司',
|
|
'effective_at' => '2026-10-01',
|
|
'expires_at' => null,
|
|
'source' => 'initial',
|
|
],
|
|
],
|
|
]);
|
|
$plans = app(CompanyPlanRepository::class);
|
|
$shops = app(CompanyPlanShopRepository::class);
|
|
$plans->importRows(1, [
|
|
[
|
|
'company_name' => '主体旧有限公司',
|
|
'taxpayer_type' => '小规模纳税人',
|
|
'business_registration_type' => '有限责任公司',
|
|
'company_status' => '已注销',
|
|
],
|
|
[
|
|
'company_name' => '主体新有限公司',
|
|
'taxpayer_type' => '一般纳税人',
|
|
'business_registration_type' => '个体工商户',
|
|
'company_status' => '正常',
|
|
],
|
|
], 'update', null);
|
|
|
|
$matcher = new ProductCostSubjectMatcher($periods, $plans, $shops);
|
|
$map = $matcher->map(['店铺A'], 1);
|
|
$old = $matcher->apply((object) [
|
|
'store_name' => '店铺A',
|
|
'occurred_date' => '2026-09-30',
|
|
], $map);
|
|
$new = $matcher->apply((object) [
|
|
'store_name' => '店铺A',
|
|
'occurred_date' => '2026-10-01',
|
|
], $map);
|
|
|
|
$this->assertSame('主体旧有限公司', $old->company_name);
|
|
$this->assertSame('2026-07-01', $old->company_effective_at);
|
|
$this->assertSame('2026-09-30', $old->company_expires_at);
|
|
$this->assertSame('已注销', $old->company_status);
|
|
$this->assertSame('小规模纳税人', $old->taxpayer_type);
|
|
$this->assertSame('有限责任公司', $old->business_registration_type);
|
|
$this->assertTrue($old->company_plan_match);
|
|
|
|
$this->assertSame('主体新有限公司', $new->company_name);
|
|
$this->assertSame('2026-10-01', $new->company_effective_at);
|
|
$this->assertNull($new->company_expires_at);
|
|
$this->assertSame('正常', $new->company_status);
|
|
$this->assertSame('一般纳税人', $new->taxpayer_type);
|
|
$this->assertSame('个体工商户', $new->business_registration_type);
|
|
$this->assertTrue($new->company_plan_match);
|
|
}
|
|
}
|