90 lines
3.5 KiB
PHP
90 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Repositories\JushuitanShopPromotionFeeMirrorRepository;
|
|
use Modules\EcommerceFinance\Services\JushuitanShopPromotionFeeSynchronizer;
|
|
use Tests\TestCase;
|
|
|
|
class SyncJushuitanShopPromotionFeeCommandTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Carbon::setTestNow('2026-12-01 10:00:00');
|
|
config()->set('services.jushuitan.shop_promotion_fee_history_start', '2026-01-01');
|
|
config()->set('services.jushuitan.shop_promotion_fee_overlap_days', 7);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
Carbon::setTestNow();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_first_run_uses_fee_dates_to_initialize_history(): void
|
|
{
|
|
$repository = Mockery::mock(JushuitanShopPromotionFeeMirrorRepository::class);
|
|
$repository->shouldReceive('initialized')->once()->andReturnFalse();
|
|
$synchronizer = Mockery::mock(JushuitanShopPromotionFeeSynchronizer::class);
|
|
$synchronizer->shouldReceive('sync')
|
|
->once()
|
|
->with(
|
|
Mockery::on(static fn (Carbon $date): bool => $date->toDateString() === '2026-01-01'),
|
|
Mockery::on(static fn (Carbon $date): bool => $date->toDateString() === '2026-12-01'),
|
|
'full',
|
|
'fee_time',
|
|
null,
|
|
)
|
|
->andReturn([
|
|
'mode' => 'full',
|
|
'time_type' => 'fee_time',
|
|
'from' => '2026-01-01',
|
|
'to' => '2026-12-01',
|
|
'pages' => 1,
|
|
'source_rows' => 2,
|
|
'stored_rows' => 2,
|
|
]);
|
|
$this->app->instance(JushuitanShopPromotionFeeMirrorRepository::class, $repository);
|
|
$this->app->instance(JushuitanShopPromotionFeeSynchronizer::class, $synchronizer);
|
|
|
|
$this->artisan('business-mirror:sync-jushuitan-shop-promotion-fees')
|
|
->expectsOutputToContain('源记录 2 条')
|
|
->assertSuccessful();
|
|
}
|
|
|
|
public function test_initialized_dataset_uses_modified_time_overlap(): void
|
|
{
|
|
$repository = Mockery::mock(JushuitanShopPromotionFeeMirrorRepository::class);
|
|
$repository->shouldReceive('initialized')->once()->andReturnTrue();
|
|
$synchronizer = Mockery::mock(JushuitanShopPromotionFeeSynchronizer::class);
|
|
$synchronizer->shouldReceive('sync')
|
|
->once()
|
|
->with(
|
|
Mockery::on(static fn (Carbon $date): bool => $date->toDateString() === '2026-11-25'),
|
|
Mockery::on(static fn (Carbon $date): bool => $date->toDateString() === '2026-12-01'),
|
|
'incremental',
|
|
'modified',
|
|
null,
|
|
)
|
|
->andReturn([
|
|
'mode' => 'incremental',
|
|
'time_type' => 'modified',
|
|
'from' => '2026-11-25',
|
|
'to' => '2026-12-01',
|
|
'pages' => 1,
|
|
'source_rows' => 1,
|
|
'stored_rows' => 1,
|
|
]);
|
|
$this->app->instance(JushuitanShopPromotionFeeMirrorRepository::class, $repository);
|
|
$this->app->instance(JushuitanShopPromotionFeeSynchronizer::class, $synchronizer);
|
|
|
|
$this->artisan('business-mirror:sync-jushuitan-shop-promotion-fees --days=7')
|
|
->expectsOutputToContain('incremental')
|
|
->assertSuccessful();
|
|
}
|
|
}
|