Перевод на доменную архитектуру

This commit is contained in:
brusnitsyn
2026-04-26 23:37:50 +09:00
parent 75ca01ffd8
commit f107ebd167
70 changed files with 4656 additions and 2070 deletions

View File

@@ -0,0 +1,92 @@
<?php
use App\Application\Reports\CompareLegacyAndNewReportUseCase;
use App\Application\Reports\DTO\GenerateReportInput;
use App\Application\Reports\DTO\ReportComparisonResult;
use App\Application\Reports\GenerateReportUseCase;
use App\Domain\Reports\Contracts\AuditLogger;
use App\Domain\Reports\Contracts\PatientSource;
use App\Domain\Reports\Contracts\ReportRepository;
use App\Domain\Reports\Models\PatientCollection;
use App\Domain\Reports\Models\ReportContext;
use App\Domain\Reports\Models\ReportSnapshot;
use App\Domain\Reports\Models\SavedReportResult;
use App\Infrastructure\Reports\Adapters\LegacyReportServiceAdapter;
it('stores generated report and writes comparison audit', function () {
$input = new GenerateReportInput(
departmentId: 10,
userId: 5015,
actorUserId: 15,
periodStart: new DateTimeImmutable('2026-04-08 06:00:00'),
periodEnd: new DateTimeImmutable('2026-04-09 06:00:00'),
reportType: 'daily',
autoFill: true,
);
$patientSource = new class implements PatientSource
{
public function load(ReportContext $context): PatientCollection
{
return new PatientCollection([], [
'payload' => [
'departmentId' => $context->departmentId,
'userId' => $context->userId,
'dates' => [$context->periodStart->getTimestamp(), $context->periodEnd->getTimestamp()],
'status' => 'submitted',
'metrics' => ['metrika_item_4' => 11],
'observationPatients' => [],
'unwantedEvents' => [],
],
]);
}
};
$snapshot = new ReportSnapshot(
departmentId: 10,
userId: 5015,
actorUserId: 15,
periodStart: new DateTimeImmutable('2026-04-08 06:00:00'),
periodEnd: new DateTimeImmutable('2026-04-09 06:00:00'),
status: 'submitted',
autoFill: true,
metrics: [4 => 11],
);
$repository = \Mockery::mock(ReportRepository::class);
$repository->shouldReceive('save')
->once()
->andReturn(new SavedReportResult(88, $snapshot));
$repository->shouldReceive('findSnapshot')
->once()
->with(88)
->andReturn($snapshot);
$adapter = \Mockery::mock(LegacyReportServiceAdapter::class);
$adapter->shouldReceive('buildSnapshotFromInput')
->once()
->andReturn($snapshot);
$comparator = new CompareLegacyAndNewReportUseCase($repository, $adapter);
$auditLogger = \Mockery::mock(AuditLogger::class);
$auditLogger->shouldReceive('logComparison')->once();
$useCase = new GenerateReportUseCase(
reportRepository: $repository,
auditLogger: $auditLogger,
comparator: $comparator,
patientSource: $patientSource,
calculators: [],
compareBeforeCutover: true,
);
$result = $useCase->handle($input);
expect($result->reportId)->toBe(88)
->and($result->usedNewArchitecture)->toBeTrue()
->and($result->comparison?->status)->toBe('matched')
->and($result->comparison?->diff)->toBe([])
->and($result->comparison?->reportId)->toBe(88);
});