55 lines
2.3 KiB
PHP
55 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Contracts\BusinessMirrorDataset;
|
|
use Modules\EcommerceFinance\Repositories\ColumnarBusinessMirrorRepository;
|
|
use Modules\EcommerceFinance\Services\ClickHouseClient;
|
|
use Tests\TestCase;
|
|
|
|
class ColumnarBusinessMirrorRepositoryTest extends TestCase
|
|
{
|
|
public function test_backfill_preserves_source_fields_and_adds_generation_metadata(): void
|
|
{
|
|
$dataset = $this->dataset();
|
|
$client = Mockery::mock(ClickHouseClient::class);
|
|
$client->shouldReceive('insertJsonEachRow')->once()->withArgs(
|
|
static function (string $table, array $columns, array $rows): bool {
|
|
return $table === 'fact_rows'
|
|
&& $columns === ['_mirror_key', 'Id', 'name', '_mirror_generation', '_mirror_synced_at', '_mirror_version']
|
|
&& $rows[0]['_mirror_key'] === 'key-1'
|
|
&& $rows[0]['Id'] === 1
|
|
&& $rows[0]['name'] === '记录一'
|
|
&& $rows[0]['_mirror_generation'] === '11111111-1111-4111-8111-111111111111'
|
|
&& is_int($rows[0]['_mirror_version']);
|
|
},
|
|
);
|
|
$repository = new ColumnarBusinessMirrorRepository($client);
|
|
|
|
$repository->storeBackfillBatch($dataset, [
|
|
['column_name' => 'Id', 'data_type' => 'int'],
|
|
['column_name' => 'name', 'data_type' => 'nvarchar'],
|
|
], [[
|
|
'_mirror_key' => 'key-1',
|
|
'Id' => 1,
|
|
'name' => '记录一',
|
|
'_mirror_synced_at' => '2026-09-07 12:00:00.000000',
|
|
]], '11111111-1111-4111-8111-111111111111');
|
|
}
|
|
|
|
private function dataset(): BusinessMirrorDataset
|
|
{
|
|
return new class implements BusinessMirrorDataset {
|
|
public function key(): string { return 'source.schema.fact'; }
|
|
public function sourceKey(): string { return 'source'; }
|
|
public function sourceSchema(): string { return 'schema'; }
|
|
public function sourceObject(): string { return 'fact'; }
|
|
public function targetTable(): string { return 'fact_rows'; }
|
|
public function keyColumns(): array { return ['Id']; }
|
|
public function watermarkColumn(): ?string { return 'updated_at'; }
|
|
public function indexDefinitions(): array { return []; }
|
|
};
|
|
}
|
|
}
|