diff --git a/tests/Service/TravelDataServiceTest.php b/tests/Service/TravelDataServiceTest.php index 80a3389..dba858f 100644 --- a/tests/Service/TravelDataServiceTest.php +++ b/tests/Service/TravelDataServiceTest.php @@ -290,6 +290,40 @@ class TravelDataServiceTest extends TestCase ], $result); } + public function testGenerateFilesMapIsMemoizedWithinRequest(): void + { + $dateId = 12345; + $hotelId = 67890; + $mapping = [ + $dateId => [ + 'id' => $dateId, + 'hotels' => [ + $hotelId => ['id' => $hotelId, 'name' => 'Test Hotel'], + ], + ], + ]; + + // Both existsLocally() calls go through generateFilesMap(); the underlying + // loader and snapshot service must each be invoked only once. + $this->travelSnapshotService + ->expects($this->exactly(2)) + ->method('exists') + ->willReturn(false); + + $this->travelLoader + ->expects($this->once()) + ->method('generateFilesMap') + ->willReturn($mapping); + + $this->travelSnapshotService + ->expects($this->once()) + ->method('generateMapping') + ->willReturn([]); + + $this->service->existsLocally($dateId, $hotelId); + $this->service->existsLocally($dateId, $hotelId); + } + public function testGetTravelDataFromLocalPrefersSnapshot(): void { $dateId = 12345;