fix: backward compatibility for new session format

This commit is contained in:
Björn Fromme
2026-03-16 12:03:00 +01:00
parent 4e05c94912
commit 78b925daa6
2 changed files with 45 additions and 5 deletions
+7 -2
View File
@@ -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
// 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;
}
}
}
+35
View File
@@ -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);
}
}