fix: backward compatibility for new session format
This commit is contained in:
@@ -377,10 +377,15 @@ class BookingDto
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
// Create a skeleton Travel with only the ID; BookingService::hydrate()
|
||||
// replaces this with the full object from cache
|
||||
$travel = new Travel();
|
||||
$travel->id = $travelId;
|
||||
$this->travel = $travel;
|
||||
// Old sessions (before c373a989) still carry a full Travel object;
|
||||
// new sessions carry only the int ID. Handle both formats.
|
||||
// TODO: Remove Travel instance branch once all pre-deploy sessions have expired
|
||||
if ($travelId instanceof Travel) {
|
||||
$this->travel = $travelId;
|
||||
} else {
|
||||
$travel = new Travel();
|
||||
$travel->id = $travelId;
|
||||
$this->travel = $travel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,39 @@ class BookingDtoTest extends TestCase
|
||||
$this->assertSame($travel, $bookingDto->travel);
|
||||
$this->assertSame(BookingDto::MODE_CREATE, $bookingDto->getMode());
|
||||
}
|
||||
|
||||
public function testUnserializeHandlesIntTravelId(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->id = 42;
|
||||
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
|
||||
|
||||
$dto = new BookingDto($travel, 1);
|
||||
$serialized = serialize($dto);
|
||||
$restored = unserialize($serialized);
|
||||
|
||||
$this->assertInstanceOf(BookingDto::class, $restored);
|
||||
$this->assertSame(42, $restored->travel->id);
|
||||
}
|
||||
|
||||
public function testUnserializeHandlesLegacyTravelObject(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->id = 42;
|
||||
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
|
||||
|
||||
// Simulate old session format where 'travel' is a full Travel object
|
||||
$data = [
|
||||
'travel' => $travel,
|
||||
'hotelId' => 1,
|
||||
];
|
||||
|
||||
$dto = new BookingDto(new Travel(), 1);
|
||||
$dto->__unserialize($data);
|
||||
|
||||
$this->assertSame($travel, $dto->travel);
|
||||
$this->assertSame(42, $dto->travel->id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user