56 lines
2.2 KiB
PHP
56 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Console;
|
|
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Contracts\BusinessMirrorDataset;
|
|
use Modules\EcommerceFinance\Repositories\GenericBusinessMirrorRepository;
|
|
use Modules\EcommerceFinance\Repositories\ProductCatalogMirrorRepository;
|
|
use Modules\EcommerceFinance\Services\BusinessMirrorDatasetRegistry;
|
|
use Modules\EcommerceFinance\Services\BusinessMirrorSynchronizer;
|
|
use Tests\TestCase;
|
|
|
|
class BusinessMirrorScheduleTest extends TestCase
|
|
{
|
|
public function test_generic_rotation_excludes_datasets_with_a_dedicated_scheduler(): void
|
|
{
|
|
config([
|
|
'upstream_mirrors.refresh_enabled' => true,
|
|
'upstream_mirrors.table_sync.dedicated_datasets' => [
|
|
ProductCatalogMirrorRepository::DATASET_KEY,
|
|
],
|
|
]);
|
|
|
|
$catalog = Mockery::mock(BusinessMirrorDataset::class);
|
|
$other = Mockery::mock(BusinessMirrorDataset::class);
|
|
$datasets = Mockery::mock(BusinessMirrorDatasetRegistry::class);
|
|
$datasets->shouldReceive('all')->once()->andReturn([
|
|
ProductCatalogMirrorRepository::DATASET_KEY => $catalog,
|
|
'test.dbo.other' => $other,
|
|
]);
|
|
$mirror = Mockery::mock(GenericBusinessMirrorRepository::class);
|
|
$mirror->shouldReceive('state')->once()->with($other)->andReturn([
|
|
'initial_completed_at' => '2026-08-01 02:00:00',
|
|
'last_attempted_at' => '2026-08-15 01:00:00',
|
|
]);
|
|
$mirror->shouldNotReceive('state')->with($catalog);
|
|
$synchronizer = Mockery::mock(BusinessMirrorSynchronizer::class);
|
|
$synchronizer->shouldReceive('sync')
|
|
->once()
|
|
->with('test.dbo.other', false, null, null)
|
|
->andReturn([
|
|
'status' => 'succeeded',
|
|
'mode' => 'incremental',
|
|
'batches' => 1,
|
|
'rows' => 10,
|
|
'dataset' => 'test.dbo.other',
|
|
]);
|
|
|
|
$this->app->instance(BusinessMirrorDatasetRegistry::class, $datasets);
|
|
$this->app->instance(GenericBusinessMirrorRepository::class, $mirror);
|
|
$this->app->instance(BusinessMirrorSynchronizer::class, $synchronizer);
|
|
|
|
$this->artisan('business-mirror:sync-tables')->assertSuccessful();
|
|
}
|
|
}
|